Powershell Cheetsheet

Conditionals

While

IF Conditional

$file = "C:\Users\user\Downloads\.zip"

if(Test-Path $file){
    Write-Host "The file exists!"
}
elseif ($file -eq "C:\Temp\test.txt"){
    Write-Host "The file is a test"
}
else{
   Write-Host "The file does not exists!"
}

For each

Get-Content "C:\Users\username\OneDrive\Desktop\IPs.txt" | % { Test-Connection -Count 1 $_  }

Last updated