Databases Reference
In-Depth Information
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 i le: 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
Interrogating Current Server Activity
When checking whether a remote computer is responsive, a good i rst place to investigate is the
ping response. Using the win32_pingstatus WMI class, this is relatively straightforward. The data
returned from this class is structured and can then be used within other parts of the investigation
or recorded back to disk in a i le, e-mailed to a recipient, or stored within a database. The following
example checks the status code (0 if successful) of a ping test on as server called SQL2012 (replace
SQL2012 with a machine name on your network):
Get-WmiObject win32_pingstatus -Filter "Address='SQL2012'" '
| Select-Object statuscode
Assuming a status code of 0 is returned from the server, you can now turn your attention to services
running on the computer. To i nd out which services are running, execute the following:
Get-Service | Where-Object { $_.Status -eq 'Running' }
The Get-Service cmdlet is very handy for simple service queries. Unfortunately, it doesn't provide
access to every property on the service. I often i nd it useful to see the Service State and the Start
Mode. Fortunately, this information is available on the Win23_Service WMI class; and the fol-
lowing script shows an example of querying this class to i nd services that start automatically with
Windows but are currently stopped. This may be useful if a server is not behaving as expected and
you suspect that a service that is usually started at boot time is currently not running.
 
Search WWH ::




Custom Search