Q. Can I use PowerShell to create and compare a configuration baseline?
A. Almost anything you can "Get" is eligible for this trick. Start by getting your baseline into an XML file. Let's say you're working with services. You'd use the command:
- Get-WmiObject -class Win32_Service | Export-CliXML baseline.xml
Then, when you're ready to compare the current state to the baseline, you'd run:
- Compare-Object (Import-CliXML baseline.xml) (Get-WmiObject -class Win32_Service)
That all gets written on one line. Compare-Object also has an alias, Diff.
The comparison will compare every attribute of those objects. That works well for many management objects such as services but not all. Processes, for example, are constantly changing. You expect a process's CPU usage, for example, to change, so you wouldn't compare everything. Instead, you'd just pick one or two properties to compare, as in:
- Compare-Object (Import-CliXML processes.xml) (Get-Process) -property name
Do you have a Windows PowerShell question? Find more PowerShell FAQs, articles, and other resources at windowsitpro.com/go/DonJonesPowerShell.