Forum Discussion
Marcel
Neophyte
3 months agoI'm working on the same and already have some scripts in place.
Auto discovery script:
$hostname = '##SYSTEM.HOSTNAME##';
Invoke-Command -ComputerName $hostname -ScriptBlock {
$vms = Get-VM | Where-Object {$_.State -eq 'Running'}
foreach ($vm in $vms)
{
$snapshots = Get-VMSnapshot -VMName $vm.Name
foreach ($snapshot in $snapshots) {
$VMName = $vm.Name
$SnapshotName = $snapshot.Name
# write out the instance data
Write-Host "$VMName##$SnapShotName";
}
}
}
# return with a response code that indicates we ran successfully
Exit 0;
Monitoring script:
$hostname = '##SYSTEM.HOSTNAME##';
Invoke-Command -ComputerName $hostname -ScriptBlock {
$vms = Get-VM | Where-Object {$_.State -eq 'Running'}
$currentDate = Get-Date
foreach ($vm in $vms)
{
$snapshots = Get-VMSnapshot -VMName $vm.Name
foreach ($snapshot in $snapshots) {
$snapshotAge = ($currentDate - $snapshot.CreationTime).Days
$VMName = $vm.Name
$SnapshotName = $snapshot.Name
$CreationTime = $snapshot.CreationTime
$AgeInDays = $snapshotAge
# write out the instance data
Write-Host "SnapshotName=${SnapshotName}";
Write-Host "VMName=${VMName}";
Write-Host "CreationTime=${CreationTime}";
Write-Host "AgeInDays=${AgeInDays}";
}
}
}
# return with a response code that indicates we ran successfully
Exit 0;
However this doesn't seem to work. What am I missing?
I also struggle to get the snapshots grouped per VM. The group method is regular expression with Parameters = useValue="value" dynamicGroup="\w+". Why doesn't this work?
Related Content
- 8 months ago
- 5 months ago