Hi All,
I there any way to use PowerCli to schedule a snapshot? I'm looking to built a script to take user inputs such as Vm name, snapshot name, snapshot date, etc. to schedule a snapshot. I'm hoping to create a simple webpage to take some user inputs and pass it to script. I saw some examples that use PowerShell to create schedule task but they are all about creating a windows scheduled task. I would like to create the task as you would create in vSphere.
Thanks,
Haluk
Hello All,
Im new VMware ,and im trying to create a script to take the snapshot for multiple vm`s ( 2000+) for an upgrade for a particular time, but the scripts mentioned in this thread is not working. i have been using the below script ,but its not throwing any error or snapshot is scheduled. So can i have the script to schedule a snapshots? or advise me if im missing anything
$snapTime = Get-Date "05/05/24 11:00"
$snapName = 'Test'
$snapDescription = 'Test Scheduled snapshot'
$snapMemory = $true
$snapQuiesce = $false
#$emailAddr = 'xxx@xxx.com'
$fileName = 'C:\Users\servers.csv'
$vcName = 'MITR004'
######################################################################
Import-Csv -Path $fileName -UseCulture | %{
$vm = Get-VM -Name $_.VMName
$si = get-view ServiceInstance
$scheduledTaskManager = Get-View $si.Content.ScheduledTaskManager
$spec = New-Object VMware.Vim.ScheduledTaskSpec
$spec.Name = "Snapshot",$vm.Name -join ' '
$spec.Description = $_.Description
$spec.Enabled = $true
$spec.Notification = $emailAddr
$spec.Scheduler = New-Object VMware.Vim.OnceTaskScheduler
$spec.Scheduler.runat = $snapTime
$spec.Action = New-Object VMware.Vim.MethodAction
$spec.Action.Name = "CreateSnapshot_Task"
@($snapName,$snapDescription,$snapMemory,$snapQuiesce) | %{
$arg = New-Object VMware.Vim.MethodActionArgument
$arg.Value = $_
$spec.Action.Argument += $arg
}
$scheduledTaskManager.CreateObjectScheduledTask($vm.ExtensionData.MoRef, $spec)
}
That script works perfectly for me.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Are you running using powershell or any other method ? im running powershell from my laptop .
can you please advise how to run it?
You can run it from any PS session, provided you have the PowerCLI modules installed.
How do you run it?
Perhaps a screenshot might help.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I use the above script
and its just connecting to the VC but its not taking any snapshot. and servers.csv just contains the vm name without any heading
The CSV file should have a column name of VMName, and the name of a VM on the next line
VMName
testvm1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Im getting the below error
Your Connect-VIServer is not working, check the $vcName variable
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Im running with the VC name ,but getting the below error
It looks as if there is no VM with the name you entered in the CSV on that vCenter.
What is in the CSV file?
Does a Get-VM return anything when using that name?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
servers,csv has 2 vm`s with VMName as header
Is there perhaps a blank line in the CSV, at the end?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I just validated , all the files and its lines looks good
Then I'm afraid I can't help you any further
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi
Im getting this error , i see the snapshot has been schedule but i have to run for a single VM at at a time, and then 2nd vm im getting the below error
I think the message is clear, that VM is in a funny state.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
any recommendations to fix ?
Test the creation of the Scheduled Tasks with other VMs.
No clue how you can fix those VMs that are in a funny state
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference