Book Image

PowerShell Troubleshooting Guide

By : Mike Shepard
Book Image

PowerShell Troubleshooting Guide

By: Mike Shepard

Overview of this book

Table of Contents (15 chapters)
PowerShell Troubleshooting Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Validating disk and memory availability


Trying to run a script on a system that is out of memory or disk space is a frustrating experience. An important piece of preparation is to determine the amount of memory and disk space present as well as how much of each is unused. Retrieving these statistics with WMI is a simple matter, and with a bit of effort we can make the results more user-friendly.

We already encountered the Win32_OperatingSystem class in the first part of this chapter. Fortunately for us, there are two properties on this class that will tell us both the total amount and the free amount of memory.

Get-CIMInstance Win32_OperatingSystem | 
  Select-object FreePhysicalMemory,TotalVisibleMemorySize 

The output on my laptop is this:

Since we're going to probably want to see these in a different unit than kilobytes, we can use a trick recommended by Jeffery Hicks (Microsoft MVP in PowerShell) to add script properties to the class returned by get-CIMInstance:

Update-TypeData -TypeName...