Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

PowerShell: Disk Space List

$
0
0

Hi All,

I'm new to PowerShell and struggling to find a way forward with using the win32_logicaldisk class within my basic script.

I have found that when I set the properties for my new object below for the win32_logicaldisk class, I will get multiple results for each property specified which is expected, and the Operating System and Computer System classes work fine as there is only one result returned

What I am trying to achieve is a result for each computer to list all available drives, their total size, free space and percentage of free space.

I don't want to filter out the device ID when getting info from the win32_logicaldisk class as all device ID's could be any letter, so I would like them all to be identified, then used for when I name my properties.

The end result would be something like this (values entered are just for the example):

C: Drive Total Size :  600.00 GB

C: Drive Free Space : 300.00 GB

C: Drive Percentage Free : 50.00%

R: Drive Total Size :  600.00 GB

R: Drive Free Space : 300.00 GB

R: Drive Percentage Free : 50.00%

I am assuming I need to run another Foreach construct for the disks and I would need to use a variable for each device ID found to use in the naming of my properties, but just can't get my head around it.

Hope someone can help.

 
PROCESS {
        foreach ($computer in $Computername) {
            $os = Get-WmiObject -Class win32_operatingsystem -Computername $Computer
            $cs = Get-WmiObject -Class win32_computersystem -Computername $Computer
            $disks = Get-WmiObject -Class win32_logicaldisk -Computername $Computer
            $props = [ordered]@{'ComputerName'=$Computer;
                'OSVersion'=$os.version;
                'OSBuild'=$os.buildnumber;
                'SPVersion'=$os.servicepackmajorversion;
                'Model'=$cs.model;
                'Manufacturer'=$cs.manufacturer;
                'RAM'=$cs.totalphysicalmemory / 1GB -as [int];
                'Sockets'=$cs.numberofprocessors;
                'Cores'=$cs.numberoflogicalprocessors;
                'SystemType'=$cs.SystemType;
                }
            $obj = New-Object -TypeName PSObject -Property $props
            Write-Output $obj
        }
    }



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>