PowerShell for Windows Admins:

WMI


June 28, 2013  11:39 AM

Refreshing values



Posted by: Richard Siddaway
PowerShell 3, WMI

The CIM cmdlets in PowerShell v3 enable you to refresh the data in the object. Try this: $p = Get-CimInstance -ClassName Win32_PerfFormattedData_PerfOS_Processor $p | Get-CimInstance | select percentprocessortime $p will remain unchanged. Another use for this is monitoring processes...

June 27, 2013  3:44 PM

Writable properties for a WMI class



Posted by: Richard Siddaway
PowerShell 3, WMI

Do you know how to discover which properties on a WMI class, and therefore a WMI instance, can be modified? Get-CimClass from the PowerShell 3.0 CIM cmdlets is the answer: $class = Get-CimClass -ClassName win32_volume $class.CimClassProperties The last command returns all of the...


June 25, 2013  12:46 PM

The inverse association



Posted by: Richard Siddaway
PowerShell, PowerShell 3, WMI

In my last post I showed how to find the groups of which a local user is a member. A comment was left asking about the inverse relationship. In this case we can just turn the code round. Get-CimInstance -ClassName Win32_Group | foreach { $users = Get-CimAssociatedInstance -InputObject...


June 24, 2013  3:23 PM

WMI association example



Posted by: Richard Siddaway
PowerShell, PowerShell 3, WMI

A question came up on the Powershell.org forum about finding the groups of which local accounts are members You can get account data using Win32_UserAccount Group information is held in Win32_Group. You can see the relationship between users and groups by dumping the Win32_GroupUser...


June 8, 2013  5:49 AM

Creating DNS PTR records



Posted by: Richard Siddaway
CIM, DNS, PowerShell 3, PowerShell v2, WMI

When I was writing the DNS chapter of PowerShell in Practice I couldn’t get the CreateInstanceFromPropertyData method on the MicrosoftDNS_PTRType class to work. Revisiting DNS for AD management in a Month of lunches this time round I have access to the CIM cmdlets so can put the parameter names...


May 20, 2013  3:50 PM

Scripting Games – Win32_LogicalDisk or Win32_Volume



Posted by: Richard Siddaway
PowerShell, Scripting Games, WMI

I have heard some discussions recently regarding whether Win32_LogicalDisk or Win32_Volume should be used in the answer to event 3 in the Scripting Games. The problem requires you pull the drive letter, drive size and freespace for local disks on the server. Notice the emphasis – that will be...


May 14, 2013  1:22 PM

Scripting Games–filtering on remote server



Posted by: Richard Siddaway
PowerShell, Scripting Games, WMI

In event 3 you have to get information on hard disk capacity. I’ve only looked at the first couple of dozen scripts but seen this too many times Get-WmiObject -Class Win32_LogicalDisk | where DriveType -eq 3 or if you prefer the version 2 way Get-WmiObject -Class Win32_LogicalDisk |...


May 7, 2013  3:00 PM

Scripting Games-don’t repeat the work



Posted by: Richard Siddaway
PowerShell, Scripting Games, WMI

There are some good features to this script but what really hurts is the two trips to the server for the Win32_Computersystem class Foreach ($IP in (Get-Content "C:\IPList.txt")) { $Name = (Get-WMIObject Win32_ComputerSystem -ComputerName $ip).Name $Mem = [math]::truncate((Get-WMIObject...


May 7, 2013  2:15 PM

Scripting Games–how not to output data



Posted by: Richard Siddaway
PowerShell, Scripting Games, WMI

I haven’t finished blogging about event 1 yet but this caught my eye. Things aren’t too bad until we hit the bunch of write-host calls $wrks = (Get-Content -path C:\IPList.txt) foreach ($wrk in $wrks) { $osver = Get-WMIObject -class win32_operatingsystem -ComputerName $wrk ...


April 30, 2013  12:32 PM

WMI vs CIM speed tests–the final round



Posted by: Richard Siddaway
PowerShell 3, WMI

As a final test I want to see what happened when I ran multiple commands against the remote machine. PS> 1..100 | foreach { Measure-Command -Expression{1..100 | foreach { Get-WmiObject -Class Win32_ComputerSystem -ComputerName W12SUS; Get-WmiObject -Class Win32_OperatingSystem...


Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: