PowerShell for Windows Admins

November 27, 2015  8:53 AM

PowerShell Summit 2016–agenda complete

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The agenda is complete on the event web site. We still have to finalise the sessions from the PowerShell Team but they will be giving a number of sessions.

November 25, 2015  7:06 PM

A deal of the day you’ll not want to miss

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Books, Powershell

PowerShell in Action, Third Edition is part of Manning’s Deal of the Day on Friday 27 November – see www.manning.com for details on the day –

Half off my book Windows PowerShell in Action, Third Edition. Use code dotd112715au at https://www.manning.com/books/windows-powershell-in-action-third-edition

November 20, 2015  10:45 AM

Creating Registry Key

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

I had a question left on the blog asking how to create a registry key. My preferred method is to use the CIM class = StdRegProv. Its a static class so you don’t need to create an object

[uint32]$hklm = 2147483650
$newkey = ‘SOFTWARE\NewKey’

Invoke-CimMethod -ClassName StdRegProv -MethodName CreateKey -Arguments @{hDefKey = $hklm; sSubKeyName = $newkey}

Define the variables for the HIVE in this case HKLM – local machine . Notice that the value has to be an unsigned integer.

The key you want to create is just the path to the key. if you need to create multiple levels of subkeys they will all create from a single path.

Then use Invoke-CimMethod to call the CreateKey method on StdRegProv. The hash table in Arguments parameter has the method parameter names and appropriate values.

If everything works you’ll get a return value of 0.

How did I know which parameters the method took?

I used Get-CimClass but that’s a story for another post.

November 20, 2015  4:13 AM

PowerShell column

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The first in a regular(ish) series of articles has been published on the TechNet UK Blog.


Covering all things PowerShell related the articles will be appearing every 3-4 weeks.

November 20, 2015  4:09 AM

Windows Server 2016 TP4

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Windows Server 2016

A new technology preview for Windows Server 2016 has just been released. Available from all good Microsoft download sites.

November 19, 2015  2:49 PM

Splatting and Default parameters

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

One thing you don’t hear much about is default parameters.

Consider this

Get-CimInstance -ClassName Win32_LogicalDisk -Filter “DeviceId = ‘C:'”

A pretty standard use of CIM.

Now think if you have to do this across a number of machines on a regular basis. Typing could get a bit tedious.

You could use splatting:

$params = @{
ClassName = ‘Win32_LogicalDisk’
Filter = “DeviceId = ‘C:'”

Get-CimInstance @params

Create a hash table of parameter names and values and use that to reduce your typing. Because its a hash table you can modify as required to use other classes or Filters

An alternative is to use default parameters

$PSDefaultParameterValues = @{
‘Get-CimInstance:ClassName’ = ‘Win32_LogicalDisk’
‘Get-CimInstance:Filter’ = “DeviceId = ‘C:'”


Use the $PSDefaultParameterValues variable to hold your default values. Note how the cmdlet and parameter are defined. You can then call the cmdlet and the default parameters and their values are applied.

If you want to override the default values you may have to do it for all of the default values for a cmdlet – in the above case the Filter is nonsensical if applied to Win32_OperatingSystem so you’d have to do this

Get-CimInstance -ClassName Win32_OperatingSystem -Filter “Manufacturer LIKE ‘%'”

Used with a bit of care splatting and default parameters are a good way to save typing

November 18, 2015  8:10 AM

Out of Process

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

One thing I’ve been seeing come up a lot recently is the problem of modules and cmdlets cot being available when jobs and workflows are executed even though the module has been specifically loaded into PowerShell.

This is because workflows and Jobs run in a separate process when you execute them – NOT your current PowerShell process. The worflow or job process doesn’t run your profile and doesn’t auto load modules.

You need to specifically perform the module import. Remember you can’t use Import-Module in a workflow so you have to wrap that part in an InlineScript block.

November 16, 2015  12:51 PM

Accessing WMI

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Powershell, WMI

There are 3 sets of cmdlets for working with WMI classes – the WMI cmdlets, the WSMAN cmdlets and the CIM cmdlets. The protocols used by these 3 sets are different.

The WMI cmdlets introduced in PowerShell 1 & 2 use DCOM for local and remote access under all circumstances

The WSMAN cmdlets introduced in PowerShell 2 use WSMAN (WinRm)

The CIM cmdlets introduced in PowerShell 3 use:

– DCOM for local access if ComputerName parameter NOT used

– WSMAN for local access IF –ComputerName parameter is used

– WSMAN (WinRM) for remote access

– WSMAN if a default CIM session is used for remote access

– DCOM if a CIM session is created using DCOM as the protocol option

The CIM cmdlets are easier to use than the WSMAN cmdlets and are the recommended way to access WMI classes.

November 14, 2015  12:51 PM

PowerShell + DevOps Global Summit 2016 – the agenda

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

We’ve finalised the agenda and we’re starting to publish session information on the web site at


There are a handful of sessions on the site at present. The rest will be added over the next week or so.

Keep checking back to see who’s been added.

Registration opens 1 December 2015

November 11, 2015  2:00 PM

WMI wildcards and filtering

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

A question on the forum asking about filtering WMI results raises a number of interesting points.

The user wanted to pass a computername and a filter term to pull product information from remote machines. I ended up with this

$computername = $env:COMPUTERNAME
$filter = ‘Live’

$scriptblock = {
Get-WmiObject -Class Win32_product -Filter “Name LIKE ‘%$filter%'” |
Select  IdentifyingNumber, Name, LocalPackage }

Invoke-Command -ComputerName $computername -ScriptBlock $scriptblock -ArgumentList $filter

You can pass an argument into the scriptblock you use with invoke-command by using the –Argumentlist parameter.

More interesting is the –Filter parameter on Get-Wmi-Object

-Filter “Name LIKE ‘%$filter%'”

Notice that % is the wildcard not * as you’d use for a string.  Its always better to filter the results from Get-WmiObject using –Filter rather than a where-object after the call.

Of course you can just use the wmi or cim cmdlets directly for this problem which is even better

Get-WmiObject -Class Win32_Product -ComputerName $computername -Filter “Name LIKE ‘%$filter%'” | Select  IdentifyingNumber, Name, LocalPackage

Get-CimInstance -ClassName Win32_Product -ComputerName $computername -Filter “Name LIKE ‘%$filter%'” | Select  IdentifyingNumber, Name, LocalPackage

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: