locked
Powershell RRS feed

  • Question

  • $computername = "Server1"
    $disks = Get-WmiObject -Class Win32_logicaldisk -ComputerName $computername | Where-Object { $_.DriveType -eq 3}
    $DriveC = $Disks | Where-Object -Property DeviceID -eq -Value 'C:'
    $DriveD = $Disks | Where-Object -Property DeviceID -eq -Value 'D:'
    $DriveE = $Disks | Where-Object -Property DeviceID -eq -Value 'E:'
    $DriveF = $Disks | Where-Object -Property DeviceID -eq -Value 'F:'
    $info = [PSCustomObject]@{
             ServerName             = $ComputerName
            'C: (GB)'               = "{0:n2}" -f (($DriveC | Select-Object -ExpandProperty Size) / 1GB)
            'Free Space on C: (GB)' = "{0:n2}" -f (($DriveC | Select-Object -ExpandProperty FreeSpace) / 1GB)
            'D: (GB)'               = "{0:n2}" -f(($DriveD | Select-Object -ExpandProperty Size) / 1GB)
            'Free Space on D: (GB)' = "{0:n2}" -f(($DriveD | Select-Object -ExpandProperty FreeSpace) / 1GB)
            'E: (GB)'               = $(if($DriveE -eq " ") { "{0:n2}" -f (($DriveE | Select-Object -ExpandProperty Size) / 1GB) } else { $DriveE =                                    "N/A"})
        }    
    $info | Format-Table

    I am trying to develop this powershell script to get disk space information from each drive on a server. Right now the script is for one server but later I will modify it to run for multiple servers.

    Different servers have different drives, like some servers have only C and D drive. Whereas some servers have E and F drive or G drive also. So I want to mention "N/A" for servers which don't have that drive in the output. What is the best way to accomplish this?

    Monday, March 4, 2019 11:33 AM

Answers

  • Hello,

    I think I was able to meet all requirements. The script will run an Invoke-Command on a remote system. The script will then query all of the disks on the system using get - <g class="gr_ gr_359 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="359" id="359">psdisk</g>. The script will also remove any CD Rom drives and exclude from the export to CSV file. Once all disk is queried output to CSV file, for drives that are missing set value as "N/A" as requested. I set the file to be created on the current users Desktop and called the file DiskQuery.csv. 

    <#
    .SYNOPSIS
        Query disk on host and export information into a CSV file.
    
    .DESCRIPTION
        Enter SystemName in $SystemName variable, for more then one system separate by commas i.e. "SYSTEMNAME1,SYSTEMNAME2"
    
    .LINK
        https://www.cit-devops.com
        https://social.technet.microsoft.com/Forums/en-US/d2b65d48-f80a-4409-ab26-82ca41c4336d/powershell?forum=winserverpowershell
    
    .EXAMPLE
    CSV file:
    "HostName",Drive_A","Drive_A_Used_GB","Drive_A_Free_GB","Drive_B","Drive_B_Used_GB","Drive_B_Free_GB","Drive_C","Drive_C_Used_GB","Drive_C_Free_GB","Drive_D","Drive_D_Used_GB","Drive_D_Free_GB","Drive_E","Drive_E_Used_GB","Drive_E_Free_GB","Drive_F","Drive_F_Used_GB","Drive_F_Free_GB","Drive_G","Drive_G_Used_GB","Drive_G_Free_GB","Drive_H","Drive_H_Used_GB","Drive_H_Free_GB","Drive_J","Drive_J_Used_GB","Drive_J_Free_GB","Drive_K","Drive_K_Used_GB","Drive_K_Free_GB","Drive_M","Drive_M_Used_GB","Drive_M_Free_GB","Drive_N","Drive_N_Used_GB","Drive_N_Free_GB","Drive_P","Drive_P_Used_GB","Drive_P_Free_GB","Drive_Q","Drive_Q_Used_GB","Drive_Q_Free_GB","Drive_R","Drive_R_Used_GB","Drive_R_Free_GB","Drive_S","Drive_S_Used_GB","Drive_S_Free_GB","Drive_T","Drive_T_Used_GB","Drive_T_Free_GB","Drive_U","Drive_U_Used_GB","Drive_U_Free_GB","Drive_V","Drive_V_Used_GB","Drive_V_Free_GB","Drive_W","Drive_W_Used_GB","Drive_W_Free_GB","Drive_X","Drive_X_Used_GB","Drive_X_Free_GB","Drive_Y","Drive_Y_Used_GB","Drive_Y_Free_GB","Drive_Z","Drive_Z_Used_GB","Drive_Z_Free_GB","Drive_A","Drive_A_Used_GB","Drive_A_Free_GB","Drive_B","Drive_B_Used_GB","Drive_B_Free_GB","Drive_C","Drive_C_Used_GB","Drive_C_Free_GB","Drive_D","Drive_D_Used_GB","Drive_D_Free_GB","Drive_E","Drive_E_Used_GB","Drive_E_Free_GB","Drive_F","Drive_F_Used_GB","Drive_F_Free_GB","Drive_G","Drive_G_Used_GB","Drive_G_Free_GB","Drive_H","Drive_H_Used_GB","Drive_H_Free_GB","Drive_J","Drive_J_Used_GB","Drive_J_Free_GB","Drive_K","Drive_K_Used_GB","Drive_K_Free_GB","Drive_M","Drive_M_Used_GB","Drive_M_Free_GB","Drive_N","Drive_N_Used_GB","Drive_N_Free_GB","Drive_P","Drive_P_Used_GB","Drive_P_Free_GB","Drive_Q","Drive_Q_Used_GB","Drive_Q_Free_GB","Drive_R","Drive_R_Used_GB","Drive_R_Free_GB","Drive_S","Drive_S_Used_GB","Drive_S_Free_GB","Drive_T","Drive_T_Used_GB","Drive_T_Free_GB","Drive_U","Drive_U_Used_GB","Drive_U_Free_GB","Drive_V","Drive_V_Used_GB","Drive_V_Free_GB","Drive_W","Drive_W_Used_GB","Drive_W_Free_GB","Drive_X","Drive_X_Used_GB","Drive_X_Free_GB","Drive_Y","Drive_Y_Used_GB","Drive_Y_Free_GB","Drive_Z","Drive_Z_Used_GB","Drive_Z_Free_GB"
    "DC01","N/A","N/A","N/A","N/A","N/A","N/A","True","14.85","44.62","True","0.01","0.98","True","0.01","0.98","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A"
    
    .NOTES
        Created by Ronnie Rosal
        Version 1
    
        For more then 1 system separated by commas
        $SystemNames = "SYSTEMNAME1,SYSTEMNAME2"
    #>
    $SystemNames = "SYSTEMNAME"
    #For more then 1 system separated by commas
    #$SystemNames = "SYSTEMNAME1,SYSTEMNAME2"
    $FolderPath = [Environment]::GetFolderPath("Desktop")
    $FileName = "DiskQuery.csv"
    
    $DriveLetters = "ABCDEFGHJKMNPQRSTUVWXYZ"
    ForEach ($DriveLetter in $DriveLetters.ToCharArray()){
        $DriveLetterHeader = $DriveLetterHeader + "," + "`"Drive_" + $DriveLetter + "`""
        $DriveLetterHeader = $DriveLetterHeader + "," + "`"Drive_" + $DriveLetter + "_Used_GB`""
        $DriveLetterHeader = $DriveLetterHeader + "," + "`"Drive_" + $DriveLetter + "_Free_GB`""
    }
    
    $DriveLetterHeader = $DriveLetterHeader.substring(1)
    Write-Output "`"HostName`",$DriveLetterHeader" | Add-Content $FolderPath\$FileName
    
    ForEach($SystemName in $SystemNames.split(",")){
        $AllDrives = Invoke-Command -ComputerName $SystemName  {Get-PSDrive | where {$_.Provider -like "*FileSystem*"}}
        $CDRomDriveLetters = Invoke-Command -ComputerName $SystemName {(Get-WMIObject -Class Win32_CDROMDrive -Property *).Drive -replace ":"}
    
    ForEach ($CDRomDriveLetter in $CDRomDriveLetters){
        $AllDrives = $AllDrives | where {$_.Name -ne $CDRomDriveLetter}
    }
    
    $AllMissingDrives = $DriveLetters.ToCharArray()
    
    ForEach ($AllDrive in $AllDrives.Name){
        $AllMissingDrives = $AllMissingDrives | where {$_ -ne $AllDrive}
    }
    
    ForEach($Drive in $AllDrives){
    
        Switch($Drive){
            {($_.Name -eq "A")}{
                $OutputDriveA = "True"
                $OutputDriveAUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveAFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "B")}{
                $OutputDriveB = "True"
                $OutputDriveBUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveBFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "C")}{
                $OutputDriveC = "True"
                $OutputDriveCUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveCFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "D")}{
                $OutputDriveD = "True"
                $OutputDriveDUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveDFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "E")}{
                $OutputDriveE = "True"
                $OutputDriveEUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveEFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "F")}{
                $OutputDriveF = "True"
                $OutputDriveFUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveFFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "G")}{
                $OutputDriveG = "True"
                $OutputDriveGUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveGFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "H")}{
                $OutputDriveH = "True"
                $OutputDriveHUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveHFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "I")}{
                $OutputDriveI = "True"
                $OutputDriveIUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveIFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "J")}{
                $OutputDriveJ = "True"
                $OutputDriveJUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveJFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "K")}{
                $OutputDriveK = "True"
                $OutputDriveKUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveKFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "L")}{
                $OutputDriveL = "True"
                $OutputDriveLUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveLFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "M")}{
                $OutputDriveM = "True"
                $OutputDriveMUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveMFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "N")}{
                $OutputDriveN = "True"
                $OutputDriveNUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveNFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "O")}{
                $OutputDriveO = "True"
                $OutputDriveOUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveOFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "P")}{
                $OutputDriveP = "True"
                $OutputDrivePUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDrivePFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "Q")}{
                $OutputDriveQ = "True"
                $OutputDriveQUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveQFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "R")}{
                $OutputDriveR = "True"
                $OutputDriveRUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveRFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "S")}{
                $OutputDriveS = "True"
                $OutputDriveSUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveSFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "T")}{
                $OutputDriveT = "True"
                $OutputDriveTUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveTFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "U")}{
                $OutputDriveU = "True"
                $OutputDriveUUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveUFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "V")}{
                $OutputDriveV = "True"
                $OutputDriveVUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveVFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "W")}{
                $OutputDriveW = "True"
                $OutputDriveWUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveWFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "X")}{
                $OutputDriveX = "True"
                $OutputDriveXUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveXFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "Y")}{
                $OutputDriveY = "True"
                $OutputDriveYUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveYFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "Z")}{
                $OutputDriveZ = "True"
                $OutputDriveZUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveZFreeGB = [math]::Round($($_.Free/1GB),2)
            }
        }
    }
    
    ForEach($MissingDrive in $AllMissingDrives){
    
        Switch($MissingDrive){
            {($_ -eq "A")}{
                $OutputDriveA = "N/A"
                $OutputDriveAUsedGB = "N/A"
                $OutputDriveAFreeGB = "N/A"
            }
            {($_ -eq "B")}{
                $OutputDriveB = "N/A"
                $OutputDriveBUsedGB = "N/A"
                $OutputDriveBFreeGB = "N/A"
            }
            {($_ -eq "C")}{
                $OutputDriveC = "N/A"
                $OutputDriveCUsedGB = "N/A"
                $OutputDriveCFreeGB = "N/A"
            }
            {($_ -eq "D")}{
                $OutputDriveD = "N/A"
                $OutputDriveDUsedGB = "N/A"
                $OutputDriveDFreeGB = "N/A"
            }
            {($_ -eq "E")}{
                $OutputDriveE = "N/A"
                $OutputDriveEUsedGB = "N/A"
                $OutputDriveEFreeGB = "N/A"
            }
            {($_ -eq "F")}{
                $OutputDriveF = "N/A"
                $OutputDriveFUsedGB = "N/A"
                $OutputDriveFFreeGB = "N/A"
            }
            {($_ -eq "G")}{
                $OutputDriveG = "N/A"
                $OutputDriveGUsedGB = "N/A"
                $OutputDriveGFreeGB = "N/A"
            }
            {($_ -eq "H")}{
                $OutputDriveH = "N/A"
                $OutputDriveHUsedGB = "N/A"
                $OutputDriveHFreeGB = "N/A"
            }
            {($_ -eq "I")}{
                $OutputDriveI = "N/A"
                $OutputDriveIUsedGB = "N/A"
                $OutputDriveIFreeGB = "N/A"
            }
            {($_ -eq "J")}{
                $OutputDriveJ = "N/A"
                $OutputDriveJUsedGB = "N/A"
                $OutputDriveJFreeGB = "N/A"
            }
            {($_ -eq "K")}{
                $OutputDriveK = "N/A"
                $OutputDriveKUsedGB = "N/A"
                $OutputDriveKFreeGB = "N/A"
            }
            {($_ -eq "L")}{
                $OutputDriveL = "N/A"
                $OutputDriveLUsedGB = "N/A"
                $OutputDriveLFreeGB = "N/A"
            }
            {($_ -eq "M")}{
                $OutputDriveM = "N/A"
                $OutputDriveMUsedGB = "N/A"
                $OutputDriveMFreeGB = "N/A"
            }
            {($_ -eq "N")}{
                $OutputDriveN = "N/A"
                $OutputDriveNUsedGB = "N/A"
                $OutputDriveNFreeGB = "N/A"
            }
            {($_ -eq "O")}{
                $OutputDriveO = "N/A"
                $OutputDriveOUsedGB = "N/A"
                $OutputDriveOFreeGB = "N/A"
            }
            {($_ -eq "P")}{
                $OutputDriveP = "N/A"
                $OutputDrivePUsedGB = "N/A"
                $OutputDrivePFreeGB = "N/A"
            }
            {($_ -eq "Q")}{
                $OutputDriveQ = "N/A"
                $OutputDriveQUsedGB = "N/A"
                $OutputDriveQFreeGB = "N/A"
            }
            {($_ -eq "R")}{
                $OutputDriveR = "N/A"
                $OutputDriveRUsedGB = "N/A"
                $OutputDriveRFreeGB = "N/A"
            }
            {($_ -eq "S")}{
                $OutputDriveS = "N/A"
                $OutputDriveSUsedGB = "N/A"
                $OutputDriveSFreeGB = "N/A"
            }
            {($_ -eq "T")}{
                $OutputDriveT = "N/A"
                $OutputDriveTUsedGB = "N/A"
                $OutputDriveTFreeGB = "N/A"
            }
            {($_ -eq "U")}{
                $OutputDriveU = "N/A"
                $OutputDriveUUsedGB = "N/A"
                $OutputDriveUFreeGB = "N/A"
            }
            {($_ -eq "V")}{
                $OutputDriveV = "N/A"
                $OutputDriveVUsedGB = "N/A"
                $OutputDriveVFreeGB = "N/A"
            }
            {($_ -eq "W")}{
                $OutputDriveW = "N/A"
                $OutputDriveWUsedGB = "N/A"
                $OutputDriveWFreeGB = "N/A"
            }
            {($_ -eq "X")}{
                $OutputDriveX = "N/A"
                $OutputDriveXUsedGB = "N/A"
                $OutputDriveXFreeGB = "N/A"
            }
            {($_ -eq "Y")}{
                $OutputDriveY = "N/A"
                $OutputDriveYUsedGB = "N/A"
                $OutputDriveYFreeGB = "N/A"
            }
            {($_ -eq "Z")}{
                $OutputDriveZ = "N/A"
                $OutputDriveZUsedGB = "N/A"
                $OutputDriveZFreeGB = "N/A"
            }
        }
    }
    Write-Output "`"$($SystemName)`",`"$OutputDriveA`",`"$OutputDriveAUsedGB`",`"$OutputDriveAFreeGB`",`"$OutputDriveB`",`"$OutputDriveBUsedGB`",`"$OutputDriveBFreeGB`",`"$OutputDriveC`",`"$OutputDriveCUsedGB`",`"$OutputDriveCFreeGB`",`"$OutputDriveE`",`"$OutputDriveEUsedGB`",`"$OutputDriveEFreeGB`",`"$OutputDriveF`",`"$OutputDriveFUsedGB`",`"$OutputDriveFFreeGB`",`"$OutputDriveG`",`"$OutputDriveGUsedGB`",`"$OutputDriveGFreeGB`",`"$OutputDriveH`",`"$OutputDriveHUsedGB`",`"$OutputDriveHFreeGB`",`"$OutputDriveJ`",`"$OutputDriveJUsedGB`",`"$OutputDriveJFreeGB`",`"$OutputDriveK`",`"$OutputDriveKUsedGB`",`"$OutputDriveKFreeGB`",`"$OutputDriveM`",`"$OutputDriveMUsedGB`",`"$OutputDriveMFreeGB`",`"$OutputDriveN`",`"$OutputDriveNUsedGB`",`"$OutputDriveNFreeGB`",`"$OutputDriveP`",`"$OutputDrivePUsedGB`",`"$OutputDrivePFreeGB`",`"$OutputDriveQ`",`"$OutputDriveQUsedGB`",`"$OutputDriveQFreeGB`",`"$OutputDriveR`",`"$OutputDriveRUsedGB`",`"$OutputDriveRFreeGB`",`"$OutputDriveS`",`"$OutputDriveSUsedGB`",`"$OutputDriveSFreeGB`",`"$OutputDriveT`",`"$OutputDriveTUsedGB`",`"$OutputDriveTFreeGB`",`"$OutputDriveU`",`"$OutputDriveUUsedGB`",`"$OutputDriveUFreeGB`",`"$OutputDriveV`",`"$OutputDriveVUsedGB`",`"$OutputDriveVFreeGB`",`"$OutputDriveW`",`"$OutputDriveWUsedGB`",`"$OutputDriveWFreeGB`",`"$OutputDriveX`",`"$OutputDriveXUsedGB`",`"$OutputDriveXFreeGB`",`"$OutputDriveY`",`"$OutputDriveYUsedGB`",`"$OutputDriveYFreeGB`",`"$OutputDriveZ`",`"$OutputDriveZUsedGB`",`"$OutputDriveZFreeGB`"" | Add-Content $FolderPath\$FileName
    }

    A sample of CSV file:

    "HostName",Drive_A","Drive_A_Used_GB","Drive_A_Free_GB","Drive_B","Drive_B_Used_GB","Drive_B_Free_GB","Drive_C","Drive_C_Used_GB","Drive_C_Free_GB","Drive_D","Drive_D_Used_GB","Drive_D_Free_GB","Drive_E","Drive_E_Used_GB","Drive_E_Free_GB","Drive_F","Drive_F_Used_GB","Drive_F_Free_GB","Drive_G","Drive_G_Used_GB","Drive_G_Free_GB","Drive_H","Drive_H_Used_GB","Drive_H_Free_GB","Drive_J","Drive_J_Used_GB","Drive_J_Free_GB","Drive_K","Drive_K_Used_GB","Drive_K_Free_GB","Drive_M","Drive_M_Used_GB","Drive_M_Free_GB","Drive_N","Drive_N_Used_GB","Drive_N_Free_GB","Drive_P","Drive_P_Used_GB","Drive_P_Free_GB","Drive_Q","Drive_Q_Used_GB","Drive_Q_Free_GB","Drive_R","Drive_R_Used_GB","Drive_R_Free_GB","Drive_S","Drive_S_Used_GB","Drive_S_Free_GB","Drive_T","Drive_T_Used_GB","Drive_T_Free_GB","Drive_U","Drive_U_Used_GB","Drive_U_Free_GB","Drive_V","Drive_V_Used_GB","Drive_V_Free_GB","Drive_W","Drive_W_Used_GB","Drive_W_Free_GB","Drive_X","Drive_X_Used_GB","Drive_X_Free_GB","Drive_Y","Drive_Y_Used_GB","Drive_Y_Free_GB","Drive_Z","Drive_Z_Used_GB","Drive_Z_Free_GB","Drive_A","Drive_A_Used_GB","Drive_A_Free_GB","Drive_B","Drive_B_Used_GB","Drive_B_Free_GB","Drive_C","Drive_C_Used_GB","Drive_C_Free_GB","Drive_D","Drive_D_Used_GB","Drive_D_Free_GB","Drive_E","Drive_E_Used_GB","Drive_E_Free_GB","Drive_F","Drive_F_Used_GB","Drive_F_Free_GB","Drive_G","Drive_G_Used_GB","Drive_G_Free_GB","Drive_H","Drive_H_Used_GB","Drive_H_Free_GB","Drive_J","Drive_J_Used_GB","Drive_J_Free_GB","Drive_K","Drive_K_Used_GB","Drive_K_Free_GB","Drive_M","Drive_M_Used_GB","Drive_M_Free_GB","Drive_N","Drive_N_Used_GB","Drive_N_Free_GB","Drive_P","Drive_P_Used_GB","Drive_P_Free_GB","Drive_Q","Drive_Q_Used_GB","Drive_Q_Free_GB","Drive_R","Drive_R_Used_GB","Drive_R_Free_GB","Drive_S","Drive_S_Used_GB","Drive_S_Free_GB","Drive_T","Drive_T_Used_GB","Drive_T_Free_GB","Drive_U","Drive_U_Used_GB","Drive_U_Free_GB","Drive_V","Drive_V_Used_GB","Drive_V_Free_GB","Drive_W","Drive_W_Used_GB","Drive_W_Free_GB","Drive_X","Drive_X_Used_GB","Drive_X_Free_GB","Drive_Y","Drive_Y_Used_GB","Drive_Y_Free_GB","Drive_Z","Drive_Z_Used_GB","Drive_Z_Free_GB"
    "DC01","N/A","N/A","N/A","N/A","N/A","N/A","True","14.85","44.62","True","0.01","0.98","True","0.01","0.98","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A"

    I hope this fulfills what you are trying to accomplish.

    This seems like a good topic to cover in my blog (www.cit-devops.com), I will write about it in the next few days in detail.

    Cheers!

    Ronnie



    • Proposed as answer by CITLead Monday, March 11, 2019 10:23 PM
    • Edited by CITLead Tuesday, March 12, 2019 12:16 AM remove random css
    • Marked as answer by Admin66 Wednesday, May 15, 2019 11:16 AM
    Monday, March 11, 2019 10:23 PM

All replies

  • You will need to learn how to write a program and design the solution you need.  What you have started with is a bit limited because of the method you have devised.  It is fixed and inflexible.

    To get multiple arbitrary results of a type it is necessary to design a solution in layers.  Each layer must contribute the resulting data.  After collecting all data then you can design a method to produce the report you require.

    The biggest issue you must resolve is how to present the data.  The challenge here is that you data is hierarchical. 

    How would you display an arbitrary list of drives per computer?  The method above is attempting to create a static object structure to display a dynamic configuration.  Start by dropping the size calculation and just return and display the disk by computer.

    This will give you the hierarchical data:

    $computers |
        ForEach-Object{
            Get-WmiObject -Class Win32_logicaldisk -Filter 'DriveType=3' -ComputerName $_
        } |
        Format-Table -Property SystemName, DeviceID, Freespace


    \_(ツ)_/


    • Edited by jrv Monday, March 4, 2019 12:56 PM
    Monday, March 4, 2019 12:52 PM
  • This way I get the servername listed multiple times for ( once for each drive), I want the servername to be listed only once and I want to list the Free space and Used space on each drive as a column and I want to handle this for multiple servers which have different drive letters.
    • Edited by Admin66 Monday, March 4, 2019 1:17 PM correction
    Monday, March 4, 2019 1:16 PM
  • This way I get the servername listed multiple times for ( once for each drive), I want the servername to be listed only once and I want to list the Free space and Used space on each drive as a column and I want to handle this for multiple servers which have different drive letters.

    Which is the point I am making.  You have to write code to convert the results into the format you want.  This is not trivial.  You have to decide what that output is and how to code it.

    You can also export to Excel and create a pivot table which will give you something close.  The issue is how to deal with missing values and how to represent thee results by computer when there per-computer results are inconsistent.

    First understand the problem.  You cannot solve a problem before you understand it.

    Another approach besides Excel is to group by computer,

    $computers |
        ForEach-Object{
            Get-WmiObject -Class Win32_logicaldisk -Filter 'DriveType=3' -ComputerName $_
        } |
        Select-Object SystemName, DeviceID, Freespace |
        Group-Object SystemName
    


    \_(ツ)_/

    Monday, March 4, 2019 2:53 PM
  • Thanks for the reply. I kind of understand what you are trying to say. However I am not able to figure out how to do this. I want to export the results to a csv file. Can you give me an example of how to deal with missing values and how to represent the results by computer when there per-computer results are inconsistent?
    Monday, March 4, 2019 3:03 PM
  • No I can't because it requires writing a solution.  You cannot export ragged data to a CSV.  It will not work.

    You can do this and open in Excel and create a pivot table.

    $computers |
        ForEach-Object{
            Get-WmiObject -Class Win32_logicaldisk -Filter 'DriveType=3' -ComputerName $_
        } |
        Export-Csv file.csv
    
    


    \_(ツ)_/

    Monday, March 4, 2019 3:47 PM
  • I don't want to create a pivot table and I know how to export the output of a command to csv.
    However I am looking for some logic which I can use to construct my if statements effectively for this case.
    And how to add columns to the same custom object at multiple layers within the script or create multiple custom objects and combine then during output.
    If there is any Microsoft documents, which explains how to achieve these kind of scenario then I can go through that as well.
    Tuesday, March 5, 2019 8:16 AM
  • Sorry but I have no idea what that means.  Are you asking how to add an object to your custom object?

    Like this?

    $computers |
        ForEach-Object{
            [pscustomobject]@{
                ComputerName = $_
                Drives = Get-WmiObject -Class Win32_logicaldisk -Filter 'DriveType=3' -ComputerName $_ |
                                Select DeviceId,Freespace
            }
        }
    


    \_(ツ)_/

    Tuesday, March 5, 2019 10:33 AM
  • Hello,

    I think I was able to meet all requirements. The script will run an Invoke-Command on a remote system. The script will then query all of the disks on the system using get - <g class="gr_ gr_359 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="359" id="359">psdisk</g>. The script will also remove any CD Rom drives and exclude from the export to CSV file. Once all disk is queried output to CSV file, for drives that are missing set value as "N/A" as requested. I set the file to be created on the current users Desktop and called the file DiskQuery.csv. 

    <#
    .SYNOPSIS
        Query disk on host and export information into a CSV file.
    
    .DESCRIPTION
        Enter SystemName in $SystemName variable, for more then one system separate by commas i.e. "SYSTEMNAME1,SYSTEMNAME2"
    
    .LINK
        https://www.cit-devops.com
        https://social.technet.microsoft.com/Forums/en-US/d2b65d48-f80a-4409-ab26-82ca41c4336d/powershell?forum=winserverpowershell
    
    .EXAMPLE
    CSV file:
    "HostName",Drive_A","Drive_A_Used_GB","Drive_A_Free_GB","Drive_B","Drive_B_Used_GB","Drive_B_Free_GB","Drive_C","Drive_C_Used_GB","Drive_C_Free_GB","Drive_D","Drive_D_Used_GB","Drive_D_Free_GB","Drive_E","Drive_E_Used_GB","Drive_E_Free_GB","Drive_F","Drive_F_Used_GB","Drive_F_Free_GB","Drive_G","Drive_G_Used_GB","Drive_G_Free_GB","Drive_H","Drive_H_Used_GB","Drive_H_Free_GB","Drive_J","Drive_J_Used_GB","Drive_J_Free_GB","Drive_K","Drive_K_Used_GB","Drive_K_Free_GB","Drive_M","Drive_M_Used_GB","Drive_M_Free_GB","Drive_N","Drive_N_Used_GB","Drive_N_Free_GB","Drive_P","Drive_P_Used_GB","Drive_P_Free_GB","Drive_Q","Drive_Q_Used_GB","Drive_Q_Free_GB","Drive_R","Drive_R_Used_GB","Drive_R_Free_GB","Drive_S","Drive_S_Used_GB","Drive_S_Free_GB","Drive_T","Drive_T_Used_GB","Drive_T_Free_GB","Drive_U","Drive_U_Used_GB","Drive_U_Free_GB","Drive_V","Drive_V_Used_GB","Drive_V_Free_GB","Drive_W","Drive_W_Used_GB","Drive_W_Free_GB","Drive_X","Drive_X_Used_GB","Drive_X_Free_GB","Drive_Y","Drive_Y_Used_GB","Drive_Y_Free_GB","Drive_Z","Drive_Z_Used_GB","Drive_Z_Free_GB","Drive_A","Drive_A_Used_GB","Drive_A_Free_GB","Drive_B","Drive_B_Used_GB","Drive_B_Free_GB","Drive_C","Drive_C_Used_GB","Drive_C_Free_GB","Drive_D","Drive_D_Used_GB","Drive_D_Free_GB","Drive_E","Drive_E_Used_GB","Drive_E_Free_GB","Drive_F","Drive_F_Used_GB","Drive_F_Free_GB","Drive_G","Drive_G_Used_GB","Drive_G_Free_GB","Drive_H","Drive_H_Used_GB","Drive_H_Free_GB","Drive_J","Drive_J_Used_GB","Drive_J_Free_GB","Drive_K","Drive_K_Used_GB","Drive_K_Free_GB","Drive_M","Drive_M_Used_GB","Drive_M_Free_GB","Drive_N","Drive_N_Used_GB","Drive_N_Free_GB","Drive_P","Drive_P_Used_GB","Drive_P_Free_GB","Drive_Q","Drive_Q_Used_GB","Drive_Q_Free_GB","Drive_R","Drive_R_Used_GB","Drive_R_Free_GB","Drive_S","Drive_S_Used_GB","Drive_S_Free_GB","Drive_T","Drive_T_Used_GB","Drive_T_Free_GB","Drive_U","Drive_U_Used_GB","Drive_U_Free_GB","Drive_V","Drive_V_Used_GB","Drive_V_Free_GB","Drive_W","Drive_W_Used_GB","Drive_W_Free_GB","Drive_X","Drive_X_Used_GB","Drive_X_Free_GB","Drive_Y","Drive_Y_Used_GB","Drive_Y_Free_GB","Drive_Z","Drive_Z_Used_GB","Drive_Z_Free_GB"
    "DC01","N/A","N/A","N/A","N/A","N/A","N/A","True","14.85","44.62","True","0.01","0.98","True","0.01","0.98","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A"
    
    .NOTES
        Created by Ronnie Rosal
        Version 1
    
        For more then 1 system separated by commas
        $SystemNames = "SYSTEMNAME1,SYSTEMNAME2"
    #>
    $SystemNames = "SYSTEMNAME"
    #For more then 1 system separated by commas
    #$SystemNames = "SYSTEMNAME1,SYSTEMNAME2"
    $FolderPath = [Environment]::GetFolderPath("Desktop")
    $FileName = "DiskQuery.csv"
    
    $DriveLetters = "ABCDEFGHJKMNPQRSTUVWXYZ"
    ForEach ($DriveLetter in $DriveLetters.ToCharArray()){
        $DriveLetterHeader = $DriveLetterHeader + "," + "`"Drive_" + $DriveLetter + "`""
        $DriveLetterHeader = $DriveLetterHeader + "," + "`"Drive_" + $DriveLetter + "_Used_GB`""
        $DriveLetterHeader = $DriveLetterHeader + "," + "`"Drive_" + $DriveLetter + "_Free_GB`""
    }
    
    $DriveLetterHeader = $DriveLetterHeader.substring(1)
    Write-Output "`"HostName`",$DriveLetterHeader" | Add-Content $FolderPath\$FileName
    
    ForEach($SystemName in $SystemNames.split(",")){
        $AllDrives = Invoke-Command -ComputerName $SystemName  {Get-PSDrive | where {$_.Provider -like "*FileSystem*"}}
        $CDRomDriveLetters = Invoke-Command -ComputerName $SystemName {(Get-WMIObject -Class Win32_CDROMDrive -Property *).Drive -replace ":"}
    
    ForEach ($CDRomDriveLetter in $CDRomDriveLetters){
        $AllDrives = $AllDrives | where {$_.Name -ne $CDRomDriveLetter}
    }
    
    $AllMissingDrives = $DriveLetters.ToCharArray()
    
    ForEach ($AllDrive in $AllDrives.Name){
        $AllMissingDrives = $AllMissingDrives | where {$_ -ne $AllDrive}
    }
    
    ForEach($Drive in $AllDrives){
    
        Switch($Drive){
            {($_.Name -eq "A")}{
                $OutputDriveA = "True"
                $OutputDriveAUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveAFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "B")}{
                $OutputDriveB = "True"
                $OutputDriveBUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveBFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "C")}{
                $OutputDriveC = "True"
                $OutputDriveCUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveCFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "D")}{
                $OutputDriveD = "True"
                $OutputDriveDUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveDFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "E")}{
                $OutputDriveE = "True"
                $OutputDriveEUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveEFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "F")}{
                $OutputDriveF = "True"
                $OutputDriveFUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveFFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "G")}{
                $OutputDriveG = "True"
                $OutputDriveGUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveGFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "H")}{
                $OutputDriveH = "True"
                $OutputDriveHUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveHFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "I")}{
                $OutputDriveI = "True"
                $OutputDriveIUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveIFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "J")}{
                $OutputDriveJ = "True"
                $OutputDriveJUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveJFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "K")}{
                $OutputDriveK = "True"
                $OutputDriveKUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveKFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "L")}{
                $OutputDriveL = "True"
                $OutputDriveLUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveLFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "M")}{
                $OutputDriveM = "True"
                $OutputDriveMUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveMFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "N")}{
                $OutputDriveN = "True"
                $OutputDriveNUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveNFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "O")}{
                $OutputDriveO = "True"
                $OutputDriveOUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveOFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "P")}{
                $OutputDriveP = "True"
                $OutputDrivePUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDrivePFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "Q")}{
                $OutputDriveQ = "True"
                $OutputDriveQUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveQFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "R")}{
                $OutputDriveR = "True"
                $OutputDriveRUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveRFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "S")}{
                $OutputDriveS = "True"
                $OutputDriveSUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveSFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "T")}{
                $OutputDriveT = "True"
                $OutputDriveTUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveTFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "U")}{
                $OutputDriveU = "True"
                $OutputDriveUUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveUFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "V")}{
                $OutputDriveV = "True"
                $OutputDriveVUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveVFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "W")}{
                $OutputDriveW = "True"
                $OutputDriveWUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveWFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "X")}{
                $OutputDriveX = "True"
                $OutputDriveXUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveXFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "Y")}{
                $OutputDriveY = "True"
                $OutputDriveYUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveYFreeGB = [math]::Round($($_.Free/1GB),2)
            }
            {($_.Name -eq "Z")}{
                $OutputDriveZ = "True"
                $OutputDriveZUsedGB = [math]::Round($($_.Used/1GB),2)
                $OutputDriveZFreeGB = [math]::Round($($_.Free/1GB),2)
            }
        }
    }
    
    ForEach($MissingDrive in $AllMissingDrives){
    
        Switch($MissingDrive){
            {($_ -eq "A")}{
                $OutputDriveA = "N/A"
                $OutputDriveAUsedGB = "N/A"
                $OutputDriveAFreeGB = "N/A"
            }
            {($_ -eq "B")}{
                $OutputDriveB = "N/A"
                $OutputDriveBUsedGB = "N/A"
                $OutputDriveBFreeGB = "N/A"
            }
            {($_ -eq "C")}{
                $OutputDriveC = "N/A"
                $OutputDriveCUsedGB = "N/A"
                $OutputDriveCFreeGB = "N/A"
            }
            {($_ -eq "D")}{
                $OutputDriveD = "N/A"
                $OutputDriveDUsedGB = "N/A"
                $OutputDriveDFreeGB = "N/A"
            }
            {($_ -eq "E")}{
                $OutputDriveE = "N/A"
                $OutputDriveEUsedGB = "N/A"
                $OutputDriveEFreeGB = "N/A"
            }
            {($_ -eq "F")}{
                $OutputDriveF = "N/A"
                $OutputDriveFUsedGB = "N/A"
                $OutputDriveFFreeGB = "N/A"
            }
            {($_ -eq "G")}{
                $OutputDriveG = "N/A"
                $OutputDriveGUsedGB = "N/A"
                $OutputDriveGFreeGB = "N/A"
            }
            {($_ -eq "H")}{
                $OutputDriveH = "N/A"
                $OutputDriveHUsedGB = "N/A"
                $OutputDriveHFreeGB = "N/A"
            }
            {($_ -eq "I")}{
                $OutputDriveI = "N/A"
                $OutputDriveIUsedGB = "N/A"
                $OutputDriveIFreeGB = "N/A"
            }
            {($_ -eq "J")}{
                $OutputDriveJ = "N/A"
                $OutputDriveJUsedGB = "N/A"
                $OutputDriveJFreeGB = "N/A"
            }
            {($_ -eq "K")}{
                $OutputDriveK = "N/A"
                $OutputDriveKUsedGB = "N/A"
                $OutputDriveKFreeGB = "N/A"
            }
            {($_ -eq "L")}{
                $OutputDriveL = "N/A"
                $OutputDriveLUsedGB = "N/A"
                $OutputDriveLFreeGB = "N/A"
            }
            {($_ -eq "M")}{
                $OutputDriveM = "N/A"
                $OutputDriveMUsedGB = "N/A"
                $OutputDriveMFreeGB = "N/A"
            }
            {($_ -eq "N")}{
                $OutputDriveN = "N/A"
                $OutputDriveNUsedGB = "N/A"
                $OutputDriveNFreeGB = "N/A"
            }
            {($_ -eq "O")}{
                $OutputDriveO = "N/A"
                $OutputDriveOUsedGB = "N/A"
                $OutputDriveOFreeGB = "N/A"
            }
            {($_ -eq "P")}{
                $OutputDriveP = "N/A"
                $OutputDrivePUsedGB = "N/A"
                $OutputDrivePFreeGB = "N/A"
            }
            {($_ -eq "Q")}{
                $OutputDriveQ = "N/A"
                $OutputDriveQUsedGB = "N/A"
                $OutputDriveQFreeGB = "N/A"
            }
            {($_ -eq "R")}{
                $OutputDriveR = "N/A"
                $OutputDriveRUsedGB = "N/A"
                $OutputDriveRFreeGB = "N/A"
            }
            {($_ -eq "S")}{
                $OutputDriveS = "N/A"
                $OutputDriveSUsedGB = "N/A"
                $OutputDriveSFreeGB = "N/A"
            }
            {($_ -eq "T")}{
                $OutputDriveT = "N/A"
                $OutputDriveTUsedGB = "N/A"
                $OutputDriveTFreeGB = "N/A"
            }
            {($_ -eq "U")}{
                $OutputDriveU = "N/A"
                $OutputDriveUUsedGB = "N/A"
                $OutputDriveUFreeGB = "N/A"
            }
            {($_ -eq "V")}{
                $OutputDriveV = "N/A"
                $OutputDriveVUsedGB = "N/A"
                $OutputDriveVFreeGB = "N/A"
            }
            {($_ -eq "W")}{
                $OutputDriveW = "N/A"
                $OutputDriveWUsedGB = "N/A"
                $OutputDriveWFreeGB = "N/A"
            }
            {($_ -eq "X")}{
                $OutputDriveX = "N/A"
                $OutputDriveXUsedGB = "N/A"
                $OutputDriveXFreeGB = "N/A"
            }
            {($_ -eq "Y")}{
                $OutputDriveY = "N/A"
                $OutputDriveYUsedGB = "N/A"
                $OutputDriveYFreeGB = "N/A"
            }
            {($_ -eq "Z")}{
                $OutputDriveZ = "N/A"
                $OutputDriveZUsedGB = "N/A"
                $OutputDriveZFreeGB = "N/A"
            }
        }
    }
    Write-Output "`"$($SystemName)`",`"$OutputDriveA`",`"$OutputDriveAUsedGB`",`"$OutputDriveAFreeGB`",`"$OutputDriveB`",`"$OutputDriveBUsedGB`",`"$OutputDriveBFreeGB`",`"$OutputDriveC`",`"$OutputDriveCUsedGB`",`"$OutputDriveCFreeGB`",`"$OutputDriveE`",`"$OutputDriveEUsedGB`",`"$OutputDriveEFreeGB`",`"$OutputDriveF`",`"$OutputDriveFUsedGB`",`"$OutputDriveFFreeGB`",`"$OutputDriveG`",`"$OutputDriveGUsedGB`",`"$OutputDriveGFreeGB`",`"$OutputDriveH`",`"$OutputDriveHUsedGB`",`"$OutputDriveHFreeGB`",`"$OutputDriveJ`",`"$OutputDriveJUsedGB`",`"$OutputDriveJFreeGB`",`"$OutputDriveK`",`"$OutputDriveKUsedGB`",`"$OutputDriveKFreeGB`",`"$OutputDriveM`",`"$OutputDriveMUsedGB`",`"$OutputDriveMFreeGB`",`"$OutputDriveN`",`"$OutputDriveNUsedGB`",`"$OutputDriveNFreeGB`",`"$OutputDriveP`",`"$OutputDrivePUsedGB`",`"$OutputDrivePFreeGB`",`"$OutputDriveQ`",`"$OutputDriveQUsedGB`",`"$OutputDriveQFreeGB`",`"$OutputDriveR`",`"$OutputDriveRUsedGB`",`"$OutputDriveRFreeGB`",`"$OutputDriveS`",`"$OutputDriveSUsedGB`",`"$OutputDriveSFreeGB`",`"$OutputDriveT`",`"$OutputDriveTUsedGB`",`"$OutputDriveTFreeGB`",`"$OutputDriveU`",`"$OutputDriveUUsedGB`",`"$OutputDriveUFreeGB`",`"$OutputDriveV`",`"$OutputDriveVUsedGB`",`"$OutputDriveVFreeGB`",`"$OutputDriveW`",`"$OutputDriveWUsedGB`",`"$OutputDriveWFreeGB`",`"$OutputDriveX`",`"$OutputDriveXUsedGB`",`"$OutputDriveXFreeGB`",`"$OutputDriveY`",`"$OutputDriveYUsedGB`",`"$OutputDriveYFreeGB`",`"$OutputDriveZ`",`"$OutputDriveZUsedGB`",`"$OutputDriveZFreeGB`"" | Add-Content $FolderPath\$FileName
    }

    A sample of CSV file:

    "HostName",Drive_A","Drive_A_Used_GB","Drive_A_Free_GB","Drive_B","Drive_B_Used_GB","Drive_B_Free_GB","Drive_C","Drive_C_Used_GB","Drive_C_Free_GB","Drive_D","Drive_D_Used_GB","Drive_D_Free_GB","Drive_E","Drive_E_Used_GB","Drive_E_Free_GB","Drive_F","Drive_F_Used_GB","Drive_F_Free_GB","Drive_G","Drive_G_Used_GB","Drive_G_Free_GB","Drive_H","Drive_H_Used_GB","Drive_H_Free_GB","Drive_J","Drive_J_Used_GB","Drive_J_Free_GB","Drive_K","Drive_K_Used_GB","Drive_K_Free_GB","Drive_M","Drive_M_Used_GB","Drive_M_Free_GB","Drive_N","Drive_N_Used_GB","Drive_N_Free_GB","Drive_P","Drive_P_Used_GB","Drive_P_Free_GB","Drive_Q","Drive_Q_Used_GB","Drive_Q_Free_GB","Drive_R","Drive_R_Used_GB","Drive_R_Free_GB","Drive_S","Drive_S_Used_GB","Drive_S_Free_GB","Drive_T","Drive_T_Used_GB","Drive_T_Free_GB","Drive_U","Drive_U_Used_GB","Drive_U_Free_GB","Drive_V","Drive_V_Used_GB","Drive_V_Free_GB","Drive_W","Drive_W_Used_GB","Drive_W_Free_GB","Drive_X","Drive_X_Used_GB","Drive_X_Free_GB","Drive_Y","Drive_Y_Used_GB","Drive_Y_Free_GB","Drive_Z","Drive_Z_Used_GB","Drive_Z_Free_GB","Drive_A","Drive_A_Used_GB","Drive_A_Free_GB","Drive_B","Drive_B_Used_GB","Drive_B_Free_GB","Drive_C","Drive_C_Used_GB","Drive_C_Free_GB","Drive_D","Drive_D_Used_GB","Drive_D_Free_GB","Drive_E","Drive_E_Used_GB","Drive_E_Free_GB","Drive_F","Drive_F_Used_GB","Drive_F_Free_GB","Drive_G","Drive_G_Used_GB","Drive_G_Free_GB","Drive_H","Drive_H_Used_GB","Drive_H_Free_GB","Drive_J","Drive_J_Used_GB","Drive_J_Free_GB","Drive_K","Drive_K_Used_GB","Drive_K_Free_GB","Drive_M","Drive_M_Used_GB","Drive_M_Free_GB","Drive_N","Drive_N_Used_GB","Drive_N_Free_GB","Drive_P","Drive_P_Used_GB","Drive_P_Free_GB","Drive_Q","Drive_Q_Used_GB","Drive_Q_Free_GB","Drive_R","Drive_R_Used_GB","Drive_R_Free_GB","Drive_S","Drive_S_Used_GB","Drive_S_Free_GB","Drive_T","Drive_T_Used_GB","Drive_T_Free_GB","Drive_U","Drive_U_Used_GB","Drive_U_Free_GB","Drive_V","Drive_V_Used_GB","Drive_V_Free_GB","Drive_W","Drive_W_Used_GB","Drive_W_Free_GB","Drive_X","Drive_X_Used_GB","Drive_X_Free_GB","Drive_Y","Drive_Y_Used_GB","Drive_Y_Free_GB","Drive_Z","Drive_Z_Used_GB","Drive_Z_Free_GB"
    "DC01","N/A","N/A","N/A","N/A","N/A","N/A","True","14.85","44.62","True","0.01","0.98","True","0.01","0.98","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A"

    I hope this fulfills what you are trying to accomplish.

    This seems like a good topic to cover in my blog (www.cit-devops.com), I will write about it in the next few days in detail.

    Cheers!

    Ronnie



    • Proposed as answer by CITLead Monday, March 11, 2019 10:23 PM
    • Edited by CITLead Tuesday, March 12, 2019 12:16 AM remove random css
    • Marked as answer by Admin66 Wednesday, May 15, 2019 11:16 AM
    Monday, March 11, 2019 10:23 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Sunday, March 31, 2019 1:01 PM