Disk information via PowerShell & WMI

Sorry for taking so much time off in between posts. Lot’s of stuff happening. So, without further waiting, here we go – the long-promised Disk Info via PowerShell & WMI.

Note, there is a filter being applied to Get-WMIObject [“Drive Type = 3”] is a local disk drive.

##Create ServerList.txt file:
sqlcmd /Lc > F:/temp/ServerList.txt

#Populate $Server_List
$Server_List = Get-Content “F:\Temp\ServerList.txt”

##Loop through $Server_List & print disks with (% FreeSpace) < X: # foreach ($row in $Server_List) { $colItems = Get-WmiObject -computername $row -class Win32_LogicalDisk -filter "DriveType = 3" Write-Host "Checking: "$row "...." Write-Host foreach ($objItem in $colItems) { [decimal]$Size = [math]::Round( (($objItem.Size) / 1.00gb) ,2) # cast to [decimal] or [long] due to [decimal]$FreeSpace = [math]::Round( (($objItem.FreeSpace) / 1.00gb) ,2) # PSH inability to cope [decimal]$Percent = [math]::Round( (($FreeSpace / $Size) * 100.00) ,2) # with UInt64 types coming at it. #if ($Percent -le 90) #{ Write-Host " Mount Point: " $objItem.DeviceID Write-Host " Volume Name: " $objItem.VolumeName Write-Host " Total Size: " $Size "GB" Write-Host " Free Space: " $FreeSpace "GB" Write-Host Write-Host " Percent Free: " $Percent"%" Write-Host #} } Write-Host Write-Host }[/sourcecode]

Explore posts in the same categories: Admin, Powershell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: