From 1a72313e20af313959f79880156e6cba15d0c9f0 Mon Sep 17 00:00:00 2001 From: ofilter Date: Tue, 5 Apr 2022 23:27:54 +0200 Subject: [PATCH] toggle --- Notes.md | 20 +++++++++++++++++++- Testing/simple_for.ps1 | 10 +++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Notes.md b/Notes.md index 59ad2ac..1bd5aa4 100644 --- a/Notes.md +++ b/Notes.md @@ -109,6 +109,12 @@ Write-Output "text" Write-Output "text" | Select-String -pattern $filters -notMatch ``` +### Select-Object + +```ps +Select-Object HostName +``` + ## File interactions ### Read file @@ -158,6 +164,8 @@ Invoke-Command -ComputerName hostname1, hostname2 -ScroptBlock {$COMMAND} ### ? https://devblogs.microsoft.com/scripting/understanding-powershell-and-basic-string-formatting/ +https://adamtheautomator.com/hyper-v-powershell/ + ## Objects ### Functions @@ -181,4 +189,14 @@ New-VM -Name "HYPER" -MemoryStartupBytes 512MB ``` ### List current VM -Get-VM \ No newline at end of file +```ps +Get-VMHost + [[-ComputerName] ] + [[-Credential] ] + [] +``` +#### Example +##### Find VM by name +```ps +Get-VM -ComputerName Server1 +``` \ No newline at end of file diff --git a/Testing/simple_for.ps1 b/Testing/simple_for.ps1 index d92652e..9e29c4d 100644 --- a/Testing/simple_for.ps1 +++ b/Testing/simple_for.ps1 @@ -32,7 +32,6 @@ host2 host3" $HYPERV_ARRAY=@() -# $i=0 foreach ($url in $HYPERV_LIST) { if ($url) @@ -40,16 +39,16 @@ host2 host3" [HypervServer]$new_hyerv=[HypervServer]::new() $new_hyerv.URL=$url $HYPERV_ARRAY+=$new_hyerv -# $i++ } } return $HYPERV_ARRAY } -function Check-Hyperv-Servers($hv_arr) { +function Check-Access($hv_arr) { foreach ($connection in $hv_arr) { - $connection.cla + Invoke-Command -ComputerName $connection.URL | out-null + $connection.Authenticated=$? } } @@ -61,10 +60,11 @@ function Print-Connections-Status($vs_arr) { } $hyperv_arr=Get-Hyperv + +Check-Access($hv_arr) #$hyperv_arr.GetType() Print-Connections-Status($hyperv_arr) -#echo "1"