Not sure what the actual question is here?
If you want to remove snapshots from multiple VMs, you will just need to adapt the line "Get-VM -Name <VM> | Get-Snapshot | Remove-Snapshot", more specifically the Get-VM cmdlet, so that it returns all the VMs you want to target.
Btw, you can also use the Send-MailMessage cmdlet to send an email.Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
LucD, Can you please help me with the script which create snapshot on multiple servers and delete.
I would like to run the script when there is a requriement on creation/deletion. Thanks in Advance.
What I was looking for:
1) My script does not work
2) If at all possible define the name of the snapshot to be deleted.
Thank you for your help!
On 1), do you get any error messages?Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
No just kept running in scheduled tasks.
First of all, your script points to: 127.0.0.1 - so unless you are running the script on your vCenter server itself, thats not going to work.
Lastly, before you put a PowerShell script into a scheduled task, you need to test it first. Then test it separately in the scheduled task area. From what I remember, to automate a PS1 task, you have to define the full powershell.exe path and then add the respective switches to execute your script.
The script should work, but as LucD rightly said, you need to remove the -Name parameter because it will expect a specific individual server rather than the entire virtual farm.
Other than that, the script looks fine.
Personally I havent done this so im not sure what it will do, but when I run a command I often have the entire action defined as a variable so that when you try to report on the outcome, you have something to echo to the screen or in this case an email as to its success code
If you run this as a scheduled task, you should remove all interactive elements (prompts).
Add the -Confirm:$false parameter on the Remove-Snapshot cmdlet.Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
1 - This is running from the vCenter
2 - the powershell path is in the scheduled task
3 - the name parameter is needed as I will be only deleting the snaps from specific VMs
Looks like that might be the missing piece, I will be testing this tonight.
This addition worked like a charm, but now I am just confirming that when I want to add additional VMs to the list it will look like this:
Get-VM -Name <VM>,<VM>,<VM> | Get-Snapshot | Remove-Snapshot -Confirm:$false
Is that correct?
I would love to test this but I don't have the chance to with the setup we have on this.
I suppose you could do that. You can also use wildcards.
Get-VM -Name (<VM>,<VM>,<VM>) | Get-Snapshot | Remove-Snapshot -Confirm:$false
Wildcard example Gathers all VM's that start w/ MyVM in their name:
Get-VM -Name MyVM* | Get-Snapshot | Remove-Snapshot -Confirm:$false