This commit is contained in:
ofilter 2022-04-05 23:27:54 +02:00
parent 393d025b14
commit 1a72313e20
2 changed files with 24 additions and 6 deletions

View File

@ -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
```ps
Get-VMHost
[[-ComputerName] <String[]>]
[[-Credential] <PSCredential[]>]
[<CommonParameters>]
```
#### Example
##### Find VM by name
```ps
Get-VM -ComputerName Server1
```

View File

@ -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"