Below is a section of a script someone else wrote and left me to clean up.
I understand most of what it's doing except one part.
If someone could break the entire section of the script down that would be break, because the rest of the script just repeats this format for different checks against VMware.
The part I'm most confused about is this one....
@{n='Result';e={ForEach ($vm1h in $vm1hs){if ($vm1h.running -eq $false){$p} else {$f}}}} |
Where is the writer getting the variable $vm1h and what's going on with ($vm1h in $vm1hs) and what is this practice called?
Thanks for your patience and I slowly try to learn scripting for the first time!
------------------------------------------------------------------------------------------
Write-Host "Checking Host Services" -ForegroundColor "Green"
$vm1hs = Get-VMHost | Get-VMHOSTService | Where {$_.Label -eq "SSH"}
$b = Get-VMHost | Get-VMHOSTService | Where {$_.Label -eq "SSH"} |
Select-Object -Property @{n='Service';e={$_.Label}},
@{n='Policy';e={$_.Policy}},
@{n='Running';e={$_.Running}},
@{n='Result';e={ForEach ($vm1h in $vm1hs){if ($vm1h.running -eq $false){$p} else {$f}}}} |
ConvertTo-Html -Fragment -PreContent "<h2>Services:</h2>" |
Out-String
$vm2hs = Get-VMHost | Get-VMHOSTService | Where {$_.Label -eq "ESXi Shell"}
$b += Get-VMHost | Get-VMHOSTService | Where {$_.Label -eq "ESXi Shell"} |
Select-Object -Property @{n='Service';e={$_.Label}},
@{n='Policy';e={$_.Policy}},
@{n='Running';e={$_.Running}},
@{n='Result';e={ForEach ($vm2h in $vm2hs){if ($vm2h.running -eq $false){$p} else {$f}}}} |
ConvertTo-Html -Fragment |
Out-String