Hi,
My Power Cli skills are limited please bear this in mind.
VSphere 6.5 running on Linux. Most of the VMs are Windows servers.
I have scheduled Snapshots in VSphere of servers just before the Monthly Windows updates are applied.
This is easy enough to do and the Snapshots are created using the naming convention e.g.: "Monthly snapshot for ServerXYZ 3rd Monday at 01:00"
Management insist Snapshots are taken just before the Windows updates every month.
Of course I want to delete the snapshots pretty quickly and we have agreed that they can be deleted after three days.
I want my PowerCli script to run on a windows 2016 server and so I have installed PowerCli and I can manually run the following commands:
Connect-VIServer -Server myvcenterserver -User Blah -Password BlahBlahBlah
this connects me to the vcenter no problem
then I run
Get-VM | Get-Snapshot | Where {$_.Name -like "*Monthly*" -and $_.Created -lt (Get-Date).AddDays(-3)} | Remove-Snapshot -Confirm:$false
sure enough this runs and deletes any snapshot more than three days old with the word Monthly in the title. Hoorah!
Im trying to automate this using a Scheduled task but im stumped on how I can get it to connect and then to carry out the "remove snapshot" bit.
Alternatively I could use SCCM to do this but I run into the same problem where regular Powershell does not seem to know about PowerCli for example:
Connect-VIServer : The term 'Connect-VIServer' is not recognized as the name of a cmdlet, etc etc
How do I get this simple command to run on a schedule?