Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 175326

avoid splitting a string if it starts with..

$
0
0

Hi all,

I have the below command:

 

Get-VM | Select Name,PowerState,

 

        @{N="IP";E={@($_.guest.IPAddress[2])}},

        @{N="OS";E={$_.ExtensionData.Config.GuestFullname}},

        @{N='VMHost';E={$_.VMHost.Name}},

        @{N="code";E={$_.name.Split('')[0].Split('-')[0]}}

 

And I have these VMs fo example:

 

abc-vm-01

abc-vm-02

abc-vm-03

def-vm-01

def-vm-02

ghi-vm-01

 

The last part "@{N="code";E={$_.name.Split('')[0].Split('-')[0]}}" will split the VM names and get:

abc

abc

abc

cde

cde

fgh

 

what can I do to get the command to split only the ones starting with "abc" and avoiding the ones that are not starting with "abc"? Like:

abc

abc

abc


Viewing all articles
Browse latest Browse all 175326

Trending Articles