Monitoring disk space utilization using powershell

Advertisements
Monitoring disk space utilization is an important task in SharePoint to avoid the critical issues , we can implemented this using PowerShell to monitor the disk utilization , in this we did not kept any threshold conditions , we are generating only report in CSV format with list of all servers available  in our  environment.
We created a config file to add all servers that you want to know the disk space utilization.
Added the server names as per the below screen shot in the text file.


Please note: we are generating this only in CSV format, it is a plane text we cannot add any colors in our output file.

Add-PSSnapin microsoft.sharepoint.powershell
$resultsarray = @()
$computers = (Get-Content "d:\Allservers.txt")
$date = Get-Date -Format “dd-MM-yyyy”
foreach($computer in $computers)
{
if([string]::isnullorwhitespace($computer))
{
}
else
{
Write-Host $computer
 $drives = Get-WmiObject -ComputerName $computer Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3}
 foreach($drive in $drives)
 {
  $contactObject = new-object PSObject
   $id = $drive.DeviceID
 $totalsize = [math]::round($drive.Size /1GB, 2)
 $freespace = [math]::round($drive.FreeSpace  / 1GB, 2)
 $usedspace= $totalsize-$freespace
 $freeprecent = [math]::round($freespace / $totalsize, 2) * 100
 $diskObject | add-member -membertype NoteProperty -name "Date" -Value $date
 $diskObject | add-member -membertype NoteProperty -name "Server Name" -Value $computer
 $diskObject | add-member -membertype NoteProperty -name "Drive" -Value $id
  $diskObject | add-member -membertype NoteProperty -name "Total GB" -Value  $totalsize     
   $diskObject | add-member -membertype NoteProperty -name "Used GB" -Value $usedspace   
 $diskObject | add-member -membertype NoteProperty -name "Free GB" -Value $freespace  
    $diskObject | add-member -membertype NoteProperty -name "% Free" -Value $freeprecent  
$resultsarray += $diskObject
}
}
}
$resultsarray| Export-csv -path "D:\diskreport_$date.csv" –notypeinformation

Delete SharePoint list items based on particular view using PowerShell


Advertisements
SHARE

lakshmitulasi Jasti

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment