VMware Cloud Community
oscarjrodriguez
Contributor
Contributor

Requesting help with decommission script

Thank you for any help or pointers.

I am trying to develop script that will

1. import a list of VMs.

2. rename append or rename the VM to their current VM name, but with this added "decomm-req#"

3.wait 7 days from when the script was run to power down the VM.

4. 7 days after the vm was powered down delete the vm from disk.

$serverlist = Get-Content  C:\Users\pgrro\Desktop\Computers.txt

foreach ($vm in $serverlist){

    

     Set-VM -VM vmname -Name vmname-decomm-C64861 -Confirm:$false

      Get-VM $VM | Stop-VM -Kill   -Confirm:$false

   

}

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

Not sure if the the script will keep running and 'sleep' for 7 days.
A better option, imho, would be to create a scheduled task, running 7 days from now.

Same goes for the delete step.


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

Reply
0 Kudos