Friday, March 15, 2019

PowerShell Script to fetch drive information for C: drive in multiple servers:


Below script will provide you the information of Disk space utilization consists of free percentage, full bock size info etc.


############################################################################################################
#                                                                                                          #
#      Author :- Swagat kumar Rout                                                                         #
# for any issues pls contact swagatkumar.rout@outlook.com                                                  #
############################################################################################################
 
 
 
$svn= cat "c:/temp/complist.txt"
$i=0;
foreach ($svn1 in $svn)
{
    $i=$i+1;
    Write-Host $i;
    Write-Host -ForegroundColor cyan "fetching information for $svn1"
    Get-WmiObject win32_Logicaldisk -ComputerName $svn1 -Filter "DeviceID='C:'" | select Name, FileSystem,FreeSpace,BlockSize,Size | % {$_.BlockSize=(($_.FreeSpace)/($_.Size))*100;$_.FreeSpace=($_.FreeSpace/1GB);$_.Size=($_.Size/1GB);$_}| Select-Object @{n="Computername";e={$svn1}},@{n="Drivename";e="name"}, @{n='FS';e={$_.FileSystem}},@{n='Free, Gb';e={'{0:N2}'-f $_.FreeSpace}}, @{n='Free,%';e={'{0:N2}'-f $_.BlockSize}},@{n='Capacity ,Gb';e={'{0:N3}' -f $_.Size}} |Export-Csv C:\temp\DisKSPACELIST.CSV -Append -Encoding UTF8 -ErrorAction SilentlyContinue
  }
 
  Write-Host -ForegroundColor Yellow "PLEASE CHECK THE FILE AT 'C:\temp\DisKSPACELIST.CSV'"

No comments:

Test Script

############################################################################## #####################################################...