Forum Discussion

Joe Schmitz's avatar
Joe Schmitz
Copper Contributor
Feb 01, 2018
Solved

Data usage report

New to Powershell.   Looking to see if there's a way to generate a report in Powershell that'll output the amount of data stored on each server's hard drives..   Thanks.   Joe
  • Pablo R. Ortiz's avatar
    Feb 03, 2018

    Let's say you have the list of Servers in C:\Servers.txt

     

    ForEach ($Server in Get-Content "C:\Servers.txt") {
      ForEach ($Disk in get-WmiObject win32_logicaldisk -Computername $Server) {
        $output = @()
        $Computer = $Disk.PSComputerName
        $Drive = $Disk.DeviceID
    $Size = "$($Disk.Size/1GB) GB" $FreeSpace = "$($Disk.FreeSpace/1GB) GB"
    $Used = "$(($Disk.Size - $Disk.FreeSpace)/1GB) GB" $Properties = @{ Computer = $Computer Drive = $Drive
    Size = $Size FreeSpace = $FreeSpace
    Used = $Used } $PSobject = New-Object -TypeName psobject -Property $Properties $output += $PSobject $output | Export-Csv -Append -Path C:\ServerDevices.CSV" -NoTypeInformation } }

Resources