dacodhack

dacodhack

Le blog d'un élève d'ESIEE-IT

2-Minute Read

PowerShell

Administration on Windows servers? No need to waste time, automate everything with PowerShell.

Variable

classics:

$variable_int = 1
$variable_string = "This is a text"

Objects:

$listeTexte=('alpha','beta')
$TableFile = @()
$table = New-Object System.Object
$table | Add-Member -type NoteProperty -name Name -Value $Name
$table | Add-Member -type NoteProperty -name Version -Value $Version
$table | Add-Member -type NoteProperty -name Hash -Value $Hash
$TableFile += $table

Function result:

$getdate = Get-Date
$(Get-Date)

Condition

Bottom and Top

10 -le 10 #true
10 -lt 11 #true
10 -gt 9 #true
10 -ge 10 #true
10 -le 09 #false
10 -lt 10 #false
10 -gt 10 #false
10 -ge 11 #false

Equality & Inequality

10 -eq 10 #true
10 -ne 20 #true
10 -eq 0 #false
10 -ne 10 #false

Loop

for

For($i=0;$i -lt 10;$i++)
{
   $i
}

foreach

foreach ($item in $collection) {
    $item
    $item.sousitem
}

while

while ($true) {
    "never stop"
}

Function

Easy Function

function Addition {
    param(
        $number1 ,
        [parameter(Mandatory = $true)] [int] $numbertwo
    )
    return $number1 + $numbertwo
}
Addition -number1 10 -numbertwo 20
#>30

Fonction utile

The most useful function is the one that allows to list all the commands on the computer.

Get-Command

Know the result of a function, or the type of a variable.

$(get-date).gettype()
$getdate.gettype()

Find the parameters of the function.

get-date | Get-Member

Fonction pour obtenir les KB installé sur l’ordinateur.

Get-HotFix

Function to get all the information of the computer such as Windows version, BIOS, Hardware.

Get-ComputerInfo

Say Something

Comments

Recent Posts

Category

About

The aim of this site is to share my experience within the school and the company.