restructuration of the files
This commit is contained in:
142
1.Basic/Learn Powershell in Less than 2 hours.md
Normal file
142
1.Basic/Learn Powershell in Less than 2 hours.md
Normal file
@@ -0,0 +1,142 @@
|
||||
# Learn Powershell in Less Than 2 hours
|
||||
|
||||
**Everything in Powershell is an Object**
|
||||
|
||||
## Widows Powershell ISE
|
||||
|
||||
To be able to write Powershell script you have a free IDE
|
||||
|
||||
## CMDLET
|
||||
|
||||
Predifine functions are names CommandLet
|
||||
Verb-Noun -Parameters
|
||||
|
||||
If you want to see all the Cmdlet available
|
||||
|
||||
```
|
||||
Get-Command -CommandTyper Cmdlet
|
||||
```
|
||||
|
||||
## PSVersionTable
|
||||
|
||||
you can see the version of powershell with the command
|
||||
|
||||
```powershell
|
||||
$PSVersionTable
|
||||
```
|
||||
|
||||
## ExecutionPolicy
|
||||
|
||||
To be able to see if you can run your Powershell scripts
|
||||
|
||||
```powershell
|
||||
Get-ExecutionPolicy
|
||||
# Work only has administrator
|
||||
Set-ExecutionPolicy remoteSigned
|
||||
```
|
||||
|
||||
### Write-Host
|
||||
|
||||
For writing in the console
|
||||
|
||||
```powershell
|
||||
Write-Host "Hello world"
|
||||
Write-Host "Hello world" -NoNewline
|
||||
Write-Host "Hello world" -BackgroundColor "Blue"
|
||||
```
|
||||
|
||||
## GetHelp
|
||||
|
||||
Print all the help articles from microsoft
|
||||
|
||||
```powershell
|
||||
Get-Help
|
||||
Get-Help Write-Host -full
|
||||
```
|
||||
|
||||
|
||||
## Piping
|
||||
|
||||
You can chain commands with "|"
|
||||
|
||||
```powershell
|
||||
Command-1 | Command-2
|
||||
"May the force be with you!" | Out-File forewithwho.txt
|
||||
```
|
||||
|
||||
|
||||
## Variables
|
||||
|
||||
They start with a "$"
|
||||
you can use strings,floating points, integer and boolean
|
||||
|
||||
```powershell
|
||||
$FavCharacter = "Spongebob"
|
||||
$FavCharacter | Out-File favcharacter.txt
|
||||
$FavCharacter.GetType()
|
||||
|
||||
$x = 5
|
||||
$y = 3
|
||||
$x + $y
|
||||
# output: 8
|
||||
|
||||
$FavCharacter | Select-Object -Property *
|
||||
# output all the Property of the variable
|
||||
Get-Member -InputObject $FaveCharacter
|
||||
# output all the mehtods you can use
|
||||
```
|
||||
|
||||
## Arrays
|
||||
|
||||
A collection of variables
|
||||
|
||||
```powershell
|
||||
$Jedi = @('Obi-Wan Kenobi', 'Luke Skywalker', 'Master Yoda', 'Mace Windu')
|
||||
|
||||
$Jedi.GetType()
|
||||
# output Object[]
|
||||
|
||||
$Jedi[0]
|
||||
# output : Obi-Wan Kenobi
|
||||
|
||||
$Jedi[0].Length
|
||||
# output 14
|
||||
|
||||
$Jedi += 'Qui-Gon Jin'
|
||||
# add a variable to the array
|
||||
```
|
||||
|
||||
## hash table
|
||||
|
||||
Specify keys
|
||||
|
||||
```powershell
|
||||
$FellowshipBeta = @{key1 = "item1"; key2 = "item2"}
|
||||
|
||||
$Fellowship = @{"Wizard" = "Gandalf"; "Elf" = "Legolas"; "Hobbit" = "Frodo"}
|
||||
|
||||
$Fellowship.Add("Dwarf", "Gimli")
|
||||
# for adding an element
|
||||
|
||||
$Fellowship.Set_Item("Dwarf", "Bilbo")
|
||||
# changing an element
|
||||
|
||||
$Fellowship."Dwarf"
|
||||
$Fellowship.["Dwarf"]
|
||||
# retrieve an element
|
||||
|
||||
$Fellowship.Remove("Dwarf")
|
||||
# Remove an element
|
||||
```
|
||||
|
||||
## Read-Host
|
||||
for having user iput
|
||||
|
||||
## Evaluatig
|
||||
|
||||
```powershell
|
||||
|
||||
$PokemonCaught = "908"
|
||||
If($PokemonCaught -eg 908) { Write-Host "You're a Pokemon Master! "}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user