Hi All,
I want Powercli script to decommission a Windows VM, I have no idea on scripting so anyone please help to share the complete script. Thanks.
Can you elaborate on what you mean by decommission, ie do you just want to delete the VM and all attached disks or do you want to perform other tasks?
Want to delete the VM and all attached disks from VC.
You'll just need to use the remove-vm powercli cmdlet with the correct parameters as per: Remove-VM - vSphere PowerCLI Cmdlets Reference
PowerCLI Getting started guide:
Hi Grba,
This will not fulfill my requirements , I need a complete script to decommission list of VM on that script.
Try the following from Powershell: Shutdown VM and Delete From Disk | Brian Gordon but ensure you test before running in a production environment as it will delete data:
Create a list of VMs to delete and store in a file named servers.txt
$VMs
= (
Get-Content
servers.txt)
$vmObj
=
Get-vm
$vms
foreach
(
$active
in
$vmObj
){
if
(
$active
.PowerState
-eq
"PoweredOn"
){
Stop-VM
-VM
$active
-Confirm
:
$false
-RunAsync
|
Out-Null
}
}
Start-Sleep
-Seconds
7
foreach
(
$delete
in
$vmObj
){
Remove-VM
-VM
$delete
-DeleteFromDisk
-Confirm
:
$false
-RunAsync
|
Out-Null
}