# Powershell ## Data storing ### Variable ```ps $x="Text" ``` ### Array ```ps $arry = @("a", "b", "c") ``` ### Hash Array [MS documentation](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_hash_tables?view=powershell-7.2) ``` $X=@{ = ; [ = ] ...} ``` ## User Interaction ### Output #### Write-Host Also accepts from redirection ``` Write-Host [[-Object] ] [-NoNewline] [-Separator ] [-ForegroundColor ] [-BackgroundColor ] [] ``` ```ps Write-Host "text" ``` #### Write-Output ```ps Write-Output "text" ``` ## Filtering ```ps Write-Output "text" | Select-String -pattern $filters -notMatch ``` ## File interactions ### Read file ```ps Get-Contents $path ``` ### write to file ```ps Write-Host $text | Out-File $path ``` ## Operators ### Check if last command executed correctly ```ps # Do something echo $? ``` ### Looping #### For #### For each ## Management ### Access remote PS server ```ps Enter-PSSession –ComputerName $hostname [-Credential username] ``` > If username gets left behind, the current user will be used ### Send command remotely ```ps Invoke-Command -ComputerName hostname1, hostname2 -ScroptBlock {$COMMAND} ``` # Hypver-V specific ## Management [//]: # (https://adamtheautomator.com/hyper-v-powershell/) ### Create new host ```ps New-VM -Name "HYPER" -MemoryStartupBytes 512MB ``` ### List current VM Get-VM