none
Get Free disk space Powershell Script RRS feed

  • Question

  • Hello EveryBody,

    I have a Script which will give me Server Name and Free Space with GB. but this script will giving me All the Drive free disk space size and number. but i am looking for only E or D drive. Can please guide me please. 

    As i don't have enough knowledge in power shell i am still learning .

    Thank you  

    Param( 
      [string]$path = "C:\Users\username\test\Freespace.html", 
      [array]$servers = @("ServerName","ServerName1","ServerName2","ServerName2",) 

     
    Function Get-DiskSpace 

     Param ([string[]]$servers) 
      Foreach ($s in $servers)  
       {  
         Get-WmiObject -Class win32_volume -cn $s | 
           Select-Object @{LABEL='Comptuer';EXPRESSION={$s}}, 
             driveletter, label,  
             @{LABEL='GBfreespace';EXPRESSION={"{0:N2}" -f ($_.freespace/1GB)}} 
        } #end foreach $s 
    } #end function Get-DiskSpace 
     
    # Entry Point *** 
     

     
    $disk = Get-DiskSpace -servers $servers |  
    ConvertTo-Html -As Table -Fragment -PreContent "<h2>Disk Report</h2>"| Out-String   
        
    ConvertTo-Html -PreContent "<h1>Backup Server Disk Space Short Report</h1>" -PostContent  $disk >> $path  


    www.aniyanetworks.net

    Tuesday, October 7, 2014 2:03 PM

All replies

  • You're going to need to work with your Get-WMIObject command to only return drive letters E:\ and D:\. I would do this by using the -Filter parameter. Take a look a my example below.

    Get-WmiObject -Class Win32_Volume -ComputerName $s -Filter "DriveLetter='E:' or DriveLetter='D:'" | ...



    Tuesday, October 7, 2014 3:26 PM
  • $Disk = Get-WmiObject -Class Win32_LogicalDisk -ComputerName $env:COMPUTERNAME  |  ? {$_.DeviceID -eq 'J:' -or $_.DeviceID -eq 'K:'} |
    Select SystemName , DeviceID , @{Name=”size(GB)”;Expression={“{0:N1}” -f($_.size/1gb)}}, @{Name=”freespace(GB)”;Expression={“{0:N1}” -f($_.freespace/1gb)}} |
    ConvertTo-Html -Fragment
    
    Convertto-html -Body "</h3>Disk report</h4>$Disk" -CssUri C:\style.CSS | Out-File C:\Temp\Disk.html

    Refer this link

    Regards Chen V [MCTS SharePoint 2010]

    Tuesday, October 7, 2014 3:38 PM