VMware Cloud Community
akohistani
Contributor
Contributor
Jump to solution

Get-VM Notes which contain specific text

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*"}

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

1 Reply
LucD
Leadership
Leadership
Jump to solution

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