I am trying to get VM Name, Notes.
Trying to find VMs with specific word in notes filed but am unable to accomplish this.
This is what I am trying:
Get-VM | Where-Object {$_.Name -notlike "_" -and $_.Notes -contains "*Text*"}
The -contains operator is meant to test if a value is present in an array of values.
You would need a -like, or even better a -match operator.
Get-VM | Where-Object {$_.Name -notlike "_" -and $_.Notes -match "Text"}
Btw, I'm not sure what the first comparison should test.
If you want to check if the Name does not contain an underscore, it would probably be better to do
Get-VM | Where-Object {$_.Name -notmatch "_" -and $_.Notes -match "Text"}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The -contains operator is meant to test if a value is present in an array of values.
You would need a -like, or even better a -match operator.
Get-VM | Where-Object {$_.Name -notlike "_" -and $_.Notes -match "Text"}
Btw, I'm not sure what the first comparison should test.
If you want to check if the Name does not contain an underscore, it would probably be better to do
Get-VM | Where-Object {$_.Name -notmatch "_" -and $_.Notes -match "Text"}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference