Iam trying to write a script to notify if a VMware VM Custom attribute has a value or if the value is null. I need the VM name and the Output Value (either Null or Not Null). Here is what I have but doesn't return the accurate information
$vms = Get-VM
foreach ($vm in $vms) {
$tag = $vm | Get-Annotation -CustomAttribute "Backup"
if ($tag.value -eq '$null'){
Write-Output "$vm Attribute doesnt have a value"
}
else {
Write-Output "$vm Attribute has a value assigned"
}
}
Unless you're specifically looking for the literal string value
'$null', you probably want to change the comparison to$null -eq $tag.valueYou could create a new object with 2 properties:
Another, perhaps more PowerShell-idiomatic approach would be to create a similar object with the
Select-Objectcmdlet: