VM_Locator/Notes.md
OriolFilter aeb411790f Update
2022-04-04 03:12:48 +02:00

1.5 KiB
Raw Blame History

Powershell

Data storing

Variable

$x="Text"

Array

$arry = @("a", "b", "c")

Hash Array

MS documentation

$X=@{ <name> = <value>; [<name> = <value> ] ...}

User Interaction

Output

Write-Host

Also accepts from redirection

Write-Host
     [[-Object] <Object>]
     [-NoNewline]
     [-Separator <Object>]
     [-ForegroundColor <ConsoleColor>]
     [-BackgroundColor <ConsoleColor>]
     [<CommonParameters>]
Write-Host "text"

Write-Output

Write-Output "text"

Filtering

Write-Output "text" | Select-String -pattern $filters -notMatch

File interactions

Read file

Get-Contents $path

write to file

Write-Host $text | Out-File $path

Operators

Check if last command executed correctly

# Do something
echo $?

Looping

For

For each

Management

Access remote PS server

Enter-PSSession ComputerName $hostname [-Credential username]

If username gets left behind, the current user will be used

Send command remotely

Invoke-Command -ComputerName hostname1, hostname2 -ScroptBlock {$COMMAND}

Hypver-V specific

Management

Create new host

New-VM -Name "HYPER" -MemoryStartupBytes 512MB

List current VM

Get-VM