Hello,
I have a simple script which schedules several snapshots of VMs from a .csv file. I'm able to see that the tasks have been creating by getting a list of all scheduled tasks:
Get-VM $VM.Name | (Get-View ScheduledTaskManager).ScheduledTask | %{(Get-View $_).Info} | Select Name,NextRunTime
How do I only get scheduled tasks for the VMs in the csv file? I'm thinking something along these lines:
$VMs = Import-Csv E:\output\VMs.csv
foreach ($VM in $VMs){
Get-VM $VM.Name | (Get-View ScheduledTaskManager).ScheduledTask | %{(Get-View $_).Info} | Select Name,NextRunTime
}
However this does not work. Any suggestions?
Thanks.
You could do something like this
$VMs = Import-Csv E:\output\VMs.csv
$vmObj = Get-VM -Name $VMs.Name
Get-View -Id (Get-View ScheduledTaskManager).ScheduledTask |
Where-Object { $_.Info.Entity -in $vmObj.Id } |
Select-Object @{N='Name';E={$_.Info.Name}}, @{N = 'NextRunTime'; E = { $_.Info.NextRunTime } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do something like this
$VMs = Import-Csv E:\output\VMs.csv
$vmObj = Get-VM -Name $VMs.Name
Get-View -Id (Get-View ScheduledTaskManager).ScheduledTask |
Where-Object { $_.Info.Entity -in $vmObj.Id } |
Select-Object @{N='Name';E={$_.Info.Name}}, @{N = 'NextRunTime'; E = { $_.Info.NextRunTime } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
