IT tutorials
 
Database
 

SQL Server 2012 : Enhancing Your Troubleshooting Toolset with Powershell (part 4) - Interrogating Disk Space Utilization

1/6/2014 2:56:27 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

3. USING POWERSHELL TO INVESTIGATE SERVER ISSUES

PowerShell provides full integration with the Windows Management Instrumentation (WMI) framework, The WMI framework is a very powerful method for querying the Windows system to find detailed information. Traditionally, it has not been easy to gain access to WMI, and this was mainly done via a programming interface. PowerShell opens up access to WMI making it a useful resource for your troubleshooting efforts.

3.1 Interrogating Disk Space Utilization

In this example, you are going to see how to make use of one of the WMI win32-logicaldisk classes to retrieve information about disk space utilization on the server. Initially, the raw information provided by the class will be returned and then the data will be used to produce a detailed analysis of disk space available:

Get-wmiobject win32_logicaldisk

Running the Get-WmiObject cmdlet and providing the win32_logicaldisk class returns the following results on my computer:

DeviceID     : C:
DriveType : 3
ProviderName :
FreeSpace : 105582891008
Size : 128742060032
VolumeName :

DeviceID : D:
DriveType : 5
ProviderName :
FreeSpace : 0
Size : 45471744
VolumeName : VBOXADDITIONS_4.

The default list view of the results is not very readable for this output, but you can improve it by formatting the output as a table:

Get-wmiobject win32-logicaldisk | format-table -autosize

On my computer this statement produces the following output:

DeviceID DriveType ProviderName    FreeSpace         Size VolumeName
-------- --------- ------------ --------- ---- ----------
C: 3 105582891008 128742060032
D: 5 0 45471744 VBOXADDITIONS_4.

You may want to filter this information so that you are only displaying fixed disks. This can be achieved by using a Filter parameter to filter the disks returned to be fixed disks only:

Get-WmiObject Win32_logicaldisk -Filter  "DriveType = 3" | Format-Table -autosize

This is getting better, but the results are being presented with the free space and the size in bytes. I can’t remember the last time when bytes were a meaningful unit of measure for a hard disk, so you can modify the script to format the output in GB (code file: PS_DiskInfo01.PS1):

$diskinfo = Get-WmiObject Win32_logicaldisk -Filter  "DriveType = 3"
$diskinfo | foreach-object {$_.FreeSpace = $_.FreeSpace / 1GB; '
$_.Size = $_.Size / 1GB}
$diskinfo | format-table -autoSize

We are now presented with a table that shows the total capacity of the drive and the available space in GB, as shown when run on my system below:

DeviceID     : C:
DriveType : 3
ProviderName :
FreeSpace : 388
Size : 466
VolumeName : OS

DeviceID : H:
DriveType : 3
ProviderName :
FreeSpace : 303
Size : 466
VolumeName : DATA
 
Others
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us