PowerShell for Windows Admins:

WMI


November 4, 2016  10:51 AM

ComputerName parameters for CIM and WMI cmdlets

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

Accessing a remote system and running Get-WmiObject -ClassName Win32_LogicalDisk -ComputerName $computer or Get-CimInstance -ClassName Win32_LogicalDisk -ComputerName $computer is a standard approach. If you’re creating a function with that code in you may put the local machine as...

November 4, 2016  10:03 AM

Working with multiple CIM objects

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

Many of the CIM objects we work with in our computers come in multiple instances – disks and network cards are a couple of examples. Many times when you see examples you’ll see something like this: $disks = Get-WmiObject -Class Win32_LogicalDisk foreach ($disk in $disks){ if ($disk.Size...


October 18, 2016  2:07 PM

Server Uptime

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

Its easy to get the last boot time of a Windows machine but how do you get the uptime function Get-Uptime { [CmdletBinding()] param ( [string]$ComputerName = $env:COMPUTERNAME ) $os = Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $ComputerName $uptime = (Get-Date) -...


October 4, 2016  12:50 PM

Filter early and WQL

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

What’s wrong with this: Get-CimInstance -ClassName Win32_Service | where {$_.State -eq 'Running' -and $_.StartName -notlike 'LocalSystem' -and $_.StartName -notlike 'NT Authority*'} | select PSComputerName, Name, DisplayName, State, StartName Nothing except that its inefficient. if you...


September 16, 2016  12:45 PM

Dealing with CIM properties that are integer arrays

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

Saw a post about WmiMonitorID that intrigued me If you use the WmiMonitorID: PS> Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorID | select -f 1 Active                 : True InstanceName           :...


August 30, 2016  12:26 PM

Optimising WMI calls–part 3

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

The next change just uses 1 call to get the disk information instead of 2 Measure-Command -Expression { $srvs = 'W16TP5TGT01', 'W16TP5TGT02' for ($i=1; $i -le 150; $i++){ foreach ($srv in $srvs) { $cs = New-CimSession -ComputerName $srv $bootupMemory = Get-CimInstance -Query "SELECT *...


August 30, 2016  11:41 AM

Optimising WMI calls–part 2

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

Last time we looked at using CIM sessions to make a set of WMI calls run quicker. This time we’ll reduce the number of calls.  I’m deliberately just reducing the number of calls to the Win32_Service class.  We’ll look at the disks another time Our code becomes Measure-Command...


June 11, 2016  4:28 AM

WMI classes and Storage cmdlets

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

There is a hierarchy of objects to work through when dealing with disks First you have the physical disk PS>  Get-CimInstance -ClassName Win32_DiskDrive | fl Partitions : 5 DeviceID   : \\.\PHYSICALDRIVE0 Model      : HFS256G3AMNB-2200A Size       :...


June 10, 2016  6:59 AM

WMI Filters

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

A common mistake with WMI/CIM filters is: PS>  Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceId=C:" Get-WmiObject : Invalid query "select * from Win32_LogicalDisk where DeviceId=C:" At line:1 char:1 + Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceId=C:" +...


April 25, 2016  8:33 AM

Cim session oddity

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
CIM, Powershell, WMI

The CIM cmdlets were introduced with PowerShell 3.0.  You can use the –ComputerName parameter to access a remote machine or, if you need to run multiple commands to the remote machine, you can create a CIM session. CIM sessions are analogous to PowerShell remoting sessions and use WSMAN by...


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: