简体   繁体   中英

powercli remove empty folders from vcenter

i have been searching for quite some time and i cant seem to find anything close. i am working on automating our VM for our DEV & QA dept using VCAC. i have reached the point that during VM creation a folder with the project's name is created under the dept (for exaple DEV\\Upgrade1)

the problem starts when the DEV guys decides to delete t the whole project and start over. i am left with a lot of empty folders throughout the VC server and i was wondering if there is a powercli script i can run daily to check if there are any empty folders (with no vms) inside and delete them if they exist.

its a tricky issue because i found i can use remove-folder but only if i give its name which i dont know. and i dont want to delete folders with VMS inside. anyone can help me? thanks

If your already connected to your server and in powercli run this.

$folders = get-folder
Foreach ($folder in $folders)
{
if((get-folder $folder|get-vm).count -eq 0)
{
 remove-folder -folder $folder -confirm $false
}
}

Drop a -location $datacenter onto the first get-folder if you want to isolate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM