VMware Cloud Community
COS
Expert
Expert

Using the function Get-InventoryPlus - How to filter for specific string in datastore

My script runs the fine below....

Get-InventoryPlus | where {$_.Type -eq 'VirtualMachine'} |

ForEach-Object -Process {

   Add-Member -InputObject $_ -MemberType NoteProperty -Name Datastore -Value ((Get-Datastore -VM $_.Name).Name -join '|')

   Add-Member -InputObject $_ -MemberType NoteProperty -Name Network -Value ((Get-VirtualPortGroup -VM $_.Name).Name -join '|') -PassThru

} |

Export-Csv C:\Temp\VM-Stuff.txt

A sample of the output...

"Guest Introspection (214)","VirtualMachine","/MIB/ESX Agents/Guest Introspection (214)","/MIB/lab_wan1/ESX Agents/Guest Introspection (214)","vmware-nsx-nfs01","dv-vm-nsx-guestinfra-174-3486|vmservice-vshield-pg"

I get that data for every VM in the datacenter.

Now I want to filter for only VM's where the datastore results contains/has the string value "-nsx-" in it?

Thanks

0 Kudos
1 Reply
LucD
Leadership
Leadership

Try like this

Get-InventoryPlus | where {$_.Type -eq 'VirtualMachine'} |

ForEach-Object -Process {

   Add-Member -InputObject $_ -MemberType NoteProperty -Name Datastore -Value ((Get-Datastore -VM $_.Name).Name -join '|')

   Add-Member -InputObject $_ -MemberType NoteProperty -Name Network -Value ((Get-VirtualPortGroup -VM $_.Name).Name -join '|') -PassThru

} | where{$_.Datastore -match "-nsx-"} |

Export-Csv C:\Temp\VM-Stuff.txt


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos