I would like to use a certain expression/property in a if statement, and also want to list a certain output. I simply don't know how to use these further down the script.
$tools = Get-VM | select name, @{N=”ToolsStatus”; E={$_.Extensiondata.Summary.Guest.ToolsStatus}}
[string]$Output = ""
foreach ($vm in $vmtools){
$Output = $Output + "$($vm.name) ----- $($vm.ToolsVersion)`n"
}
if ("ToolsStatus" -eq "toolsOld") {
Write-Output "CRITICAL, These VM's have out of date tools: `n $Output"
$Status = 2 enter code here
- How do I go about using "ToolStatus"/E={$_.Extensiondata.Summary.Guest.ToolsStatus}} in my if statement?
- I know that i can use $vm.name to list the names, but let's say I wanted to have the output from @{N=”ToolsStatus”; E={$_.Extensiondata.Summary.Guest.ToolsStatus}} as well?
$toolshere will contain a collection of VM objects with propertiesNameandToolStatus.$tools.ToolStatusreturns the value of allToolStatusproperties for every object in$tools. For comparing a single value to a collection of values, you can use either the-containsor the-inoperator.When you use
Select-Object, you create a custom object with the properties that you have selected.ToolStatushere is a calculated property. Even though the syntax is different to create the property as opposed to just typing the name of a property, you still retrieve its value the same as any other property on your object. It is easiest to use the member access operator.in the syntaxobject.property.