Skip to content

Commit 760ec93

Browse files
authored
Create powercli-vmware-snapshots.ps1
1 parent 3be1fbd commit 760ec93

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

powercli-vmware-snapshots.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Function Get-VIScheduledTasks {
2+
PARAM ( [switch]$Full )
3+
if ($Full) {
4+
# Note: When returning the full View of each Scheduled Task, all date times are in UTC
5+
(Get-View ScheduledTaskManager).ScheduledTask | %{ (Get-View $_).Info }
6+
} else {
7+
# By default, lets only return common headers and convert all date/times to local values
8+
(Get-View ScheduledTaskManager).ScheduledTask | %{ (Get-View $_ -Property Info).Info } |
9+
Select-Object Name, Description, Enabled, Notification, LastModifiedUser, State, Entity,
10+
@{N=EntityName;E={ (Get-View $_.Entity -Property Name).Name }},
11+
@{N=LastModifiedTime;E={$_.LastModifiedTime.ToLocalTime()}},
12+
@{N=NextRunTime;E={$_.NextRunTime.ToLocalTime()}},
13+
@{N=PrevRunTime;E={$_.LastModifiedTime.ToLocalTime()}},
14+
@{N=ActionName;E={$_.Action.Name}}
15+
}
16+
}
17+
Function Get-VMScheduledSnapshots {
18+
Get-VIScheduledTasks | ?{$_.ActionName -eq CreateSnapshot_Task} |
19+
Select-Object @{N=VMName;E={$_.EntityName}}, Name, NextRunTime, Notification
20+
}
21+
Function Remove-VIScheduledTask {
22+
PARAM ([string]$taskName)
23+
(Get-View -Id ((Get-VIScheduledTasks -Full | ?{$_.Name -eq $taskName}).ScheduledTask)).RemoveScheduledTask()
24+
}

0 commit comments

Comments
 (0)