VMware Cloud Community
chakoe
Enthusiast
Enthusiast

How to check, if an folder exists?

Hi all,

is it possible to check, if a folder ( type = VM ) exists in the Vcenter? How?

Thanks in advance

Chakoe

0 Kudos
1 Reply
kunaludapi
Expert
Expert

#change here foldername to check

$foldername = "test"

$data = get-folder -Type VM | Where-Object {$_.name -eq $foldername}

if ($data -eq $null) {

    Write-Host "$foldername Folder doesn't exist" -BackgroundColor Red

}

else {

    Write-Host "$foldername Folder exists" -BackgroundColor DarkGreen

}

for complete report just use command

Get-Folder

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos