Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 168455

Re: using -match I want to write output in a statement

$
0
0

In $array you have a number of PSCustomObject entries, where each has an IP property.

You could find the match/nomatch like this

 

#Connect-VIServer vct-00-ls

#

#$match_address = Read-Host "Enter the ip address of the vm to search for "

#

##$array = Get-VM | Select Name, @{N="IP Address";E={@($_.guest.IPAddress)}}

 

 

# Specify vCenter Server

###Prompt for the virtual center to connect to

$vCenterName=Read-host"Enter the virtual center server name that you wish to connect to"

 

###Provide User id and password

$vcentercred=Get-Credential-Message"Enter the user name and password to login to $vCenterName "

 

###Connecting to the vCenter/ESX server

write-host"Connecting to vCenter Server $vCenterName"-foregroundgreen

Connect-viserver$vCenterName-Credential$vcentercred

Write-Host" "

 

$match_address=Read-Host"Enter the ip address of the vm to search for "

 

$array=Get-View-ViewTypeVirtualMachine|SelectName, @{N='IP';E={[string]::Join(',',$_.Guest.net.IPAddress)}}

 

$vm=$array|where{$_.IP -match$match_address}

 

if($vm){

    Write-Output"Match found $($vm.Name)"

}

else{

    Write-Output"No match found"

}

 

Write-Host"Disconnecting from"$VcenterName.-ForegroundColorRed

Disconnect-VIServer$VcenterName-Confirm:$False


Viewing all articles
Browse latest Browse all 168455

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>