Powershell: Warnung bei Mehr als 10 .AVHDX Dateien
z.B. unter
C:\ClusterStorage\S2DDaten01\Skripts\Check_AVHDx_Count.ps1
ablegen.
cls
$PSEmailServer = "mail.yourdomain.com"
cd 'C:\ClusterStorage\S2DDaten01\Hyper-V\'
$Paths = Get-ChildItem 'C:\ClusterStorage\S2DDaten01\Hyper-V\' -Recurse | foreach {If ($_.psiscontainer) {$_.fullname}}
foreach ($Path in $Paths){
$check = ((Get-ChildItem $Path *.avhdx).Count -gt 10)
if ( $check -eq $true){
$data = Get-ChildItem $Path *.avhdx | Sort-Object LastWriteTime -Descending
$VMString = $data[0]
$VMNAMELONG = $VMString.Name
$VMNAME = $VMNAMELONG.Split('_')[0]
$msgSubject = $VMNAME
Send-MailMessage -to "alarm@yourdomain.com" -from "Cluster20 AVHDx Check <ps@yourdomain.com>" -Subject "AVHDx Checks für VM: $msgSubject" -body ($data | Out-String) -Encoding UTF8
}
}
Schreibe einen Kommentar