This is script below,
#array with the server name to check $serversToCheck="servername" #array tostore the results $results=@() #loop through the list of servers..... foreach ($server in $serversToCheck) { #get information about the server logical disk drives(include only the drive,size and free space $diskList=Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" -computerName $server | select-Object -Property Name, Size, FreeSpace #loop through the server drives and add a few custom properties foreach ($disk in $diskList) { add-member -inputobject $disk -type noteproperty -name Machine -value $server; add-member -inputobject $disk -type noteproperty -name PrecentFree -value ([long]$disk.freespace/[long]$disk.Size); add-member -inputobject $disk -type scriptproperty -name Status -value { if($this.PrecentFree -lt 0.20){"CRITTICAL"} elseif ($this.PrecentFree -lt 0.35) {"WARNING"}else{"OK"}}; #add the drive info to the result array $results += $disk; } } #return from the results only data for drives with status different than Ok #format the output in table, grouped by server name, with size in GB $badDisks = $results | where-object -filterScript {$-.Status -ne "OK"} #check if there are any disks which are running on low disk space if ($badDisks) { #format the output (store it in a file) $badDisks | format-table -groupBy Machine -Property @{lable="Drive";expression={$_.Name}}, @{lable="Disk Size ";expression={"{0,7:N2} GB" -f ($_.Size / 1gb)}}, @{lable="Free Space"; expression={"{0,72:N2} GB" -f($_.FreeSpace / 1gb)}}, @{lable="Precent Free";expression={"{0,12:P}" -f $_.PrecentFree}}, @{lable="Free Status";expression={$_.Status}} | out-file "D:\ananda\powershell\baddisk.txt" -encoding Unicode [string]$msg=get-content -path "D:\ananda\powershell\baddisks.txt" -encoding Unicode
#send out an alert e-mail $SmtpClient = new-object system.net.mail.smtpclient ("10.4.54.22") #$SmtpClient.host $From="Diskspacealert@ril.com" $to="ananda.murugesan@ril.com" $Title="Low disk space alert" $Body="The following drive are runnning low on diskspace 'n" + $msg $SmtpClient.send($from,$to,$title,$body) }
I could not able to correct this error, Pl can anyone help me .
Error details:
The term '$-.Status' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again. At D:\DC\DiskspaceAlert.ps1:28 char:61 + $badDisks = $results | where-object -filterScript {$-.Status <<<< -ne "OK"} The term '$-.Status' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again. At D:\DC\DiskspaceAlert.ps1:28 char:61 + $badDisks = $results | where-object -filterScript {$-.Status <<<< -ne "OK"}
thanks
|