VMware Cloud Community
vrm
Contributor
Contributor
Jump to solution

Need PowerCLI code to check wether a virtual exist or not

Hello,

Can someone give me an example of the PowerCLI code to check wether a virtual exist or not?

Vincent

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I assume you want to check if a vritual machine exists or not.

One, simple, method of doing this could be

$MyVM = Get-VM -Name "DoYouExist" -ErrorAction SilentlyContinue
if($MyVM -eq $null){
    Write-Host "VM doesn't exist"
}

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

I assume you want to check if a vritual machine exists or not.

One, simple, method of doing this could be

$MyVM = Get-VM -Name "DoYouExist" -ErrorAction SilentlyContinue
if($MyVM -eq $null){
    Write-Host "VM doesn't exist"
}

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
vrm
Contributor
Contributor
Jump to solution

That's what was I'm looking for! Thanks for the help.

0 Kudos