PowerShell for Windows Admins

March 10, 2012  5:44 AM

Migrating to CIM-part 2

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

We need to find the parameters associated with a WMI method – this information has to include the parameter and data type.  WMI also gives a name to the output variable – this becomes a property on the return object.

function get-CIMmethod {            
param (            
$r = Get-CimClass -Namespace $namespace -ClassName $classname             
if ($methodname) {            
 $r.CimClassMethods | where Name -eq $methodname |            
 foreach {            
    $_ | select -ExpandProperty Parameters | Format-Table -Wrap            
else {            

For this task we use Get-CimClass. Think of it as Get-WmiObject –List but with more bells and whistles.

The parameters are a namespace, and class name and an optional method name

The object representing the class information is put into a variable $r

If we don’t specify  a method name we get a summary listing of all methods.

If we do specify a method name we get the summary of the method and an expanded view of the parameters that includes name, type and whether its input (IN) or output (OUT)

Name            CimType Qualifiers

—-            ——- ———-

hDefKey          UInt32 {ID, IN}

sSubKeyName      String {ID, IN}

sNames      StringArray {ID, out}

The other point to note in this function is the simplified where-object syntax. Normally we would use

where {$_.Name –eq $methodname}

but in PowerShell v3 we can simplify to

where Name –eq $methodname

March 10, 2012  5:18 AM

Migrating to CIM–part 1

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I have created many WMI posts on this blog over the years. With PowerShell v3 a new API has been introduced and new cmdlets are available for working with WMI. The new functionality offers many improvements and advantages over using the WMI cmdlets so I thought that a series of articles showing the evolution of a piece of WMI based PowerShell might be useful.

Much of our work with WMI is based on retrieving data e.g.

Get-WmiObject -Class Win32_ComputerSystem

In PowerShell v3 this could become

Get-CimInstance -ClassName Win32_ComputerSystem


OK that seems simple but what about using the WMI type accelerators

$HKLM = 2147483650            
$key = "SYSTEM\CurrentControlSet\Services"            
$reg = [wmiclass]'\\.\root\default:StdRegprov'            
$subkeys = $reg.EnumKey($HKLM, $key)            

These don’t exist in the CIM cmdlets.  What we do have is Invoke-CimMethod so we can do this

[uint32]$HKLM = 2147483650            
$key = "SYSTEM\CurrentControlSet\Services"            
Invoke-CimMethod -Namespace "root\default" -ClassName StdRegProv -MethodName EnumKey  -Arguments @{hDefKey=$HKLM; sSubKeyName =$key} |            
select -ExpandProperty sNames

There are a few important points we need to note:

  • The value to define the hive has to be an unsigned integer
  • we have to supply the correct argument name
  • The arguments are provided in a hash table
  • ClassName is used instead of class
  • The results are a collection that we have to expand

So how do we find this information – see part 2

March 8, 2012  1:36 PM

PowerShell web access

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Would you like to be able to access a PowerShell console in a web browser to manage your remote machines?

You would – then PowerShell web access in Windows Server 8 is just for you

Introductory details here:


March 6, 2012  12:50 PM

PowerShell v3 in Depth–offer

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


I announced the availability of PowerShell v3 in Depth on Manning’s Early Access Programme


Now you have an opportunity to get this book by Don Jones, Jeff Hicks and myself at a significant bargain.  Buy from www.manning.com and get a 50% discount using the code is "PSID12". The offer is valid through Friday 9 March 2012.

March 6, 2012  12:45 PM

UK PowerShell group–March 2012

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Here are the details of the March meeting

When: Tuesday, Mar 27, 2012 7:30 PM (GMT)

Where: Virtual


PowerShell v3 introduces a new way of working with WMI plus the option of creating your own cmdlets directly from WMI classes


Richard Siddaway has invited you to attend an online meeting using Live Meeting.
Join the meeting.
Audio Information
Computer Audio
To use computer audio, you need speakers and microphone, or a headset.
First Time Users:
To save time before the meeting, check your system to make sure it is ready to use Microsoft Office Live Meeting.
Unable to join the meeting? Follow these steps:

  1. Copy this address and paste it into your web browser:
  2. Copy and paste the required information:
    Meeting ID: BDFCK7
    Entry Code: rfF^w>$3X
    Location: https://www.livemeeting.com/cc/usergroups

If you still cannot enter the meeting, contact support

Microsoft Office Live Meeting can be used to record meetings. By participating in this meeting, you agree that your communications may be monitored or recorded at any time during the meeting.

March 4, 2012  2:45 PM

Upload through BITS

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Downloading through BITS is easy as we have seen,  Uploading requites some work. First the BITS IIS extensions have to be loaded.  Restart IIS and look at the properties of the Virtual Directory being used for the transfer.  At the bottom you should find a BITS upload option in the Other section.  Double click and enable uploads.  Configure other properties as desired.

A single file upload can be achieved like this

Start-BitsTransfer -Source c:\source\transfer\testupload.txt -Destination http://webr201/transfer/testupload.txt -TransferType Upload

For multiple file uploads try this

Import-Module BitsTransfer -Force            
$computername = "WebR201"            
$source = "c:\source\transfer\"            
Get-ChildItem -Path $source |            
foreach {            
$destination =  "http://webr201/transfer/$($_.name)"            
Write-Host "Transferring $($_.Fullname) to $destination"            
Start-BitsTransfer -Source $($_.Fullname) -Destination $destination -TransferType Upload            

Import the module. Set the machine name & source folder. Run Get-ChildItem over the folder and for each file set up a BITS transfer source and destination variables using the name and fullname. Run the transfer.

March 4, 2012  7:27 AM

Windows Server 8–features removed or deprecated

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

When you start your implementation planning for Windows Server 8 make sure to check with this page for functionality that has been removed or deprecated (means it will be removed in a future version)


March 3, 2012  8:26 AM

Windows 8 svchost

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

When you run get-process you will see a number of entries named svchost.  These are processes that host services. In task manager on Windows 7 and below all we see is the svchost entry. In the Windows 8 family we see the services running in a particular host

Now can we do anything similar with PowerShell.

Get-Service doesn’t do anything to help BUT the Win32_Service class has a ProcessID property that we can use

Get-CimInstance -ClassName Win32_Service |             
sort ProcessID -Descending |            
foreach {            
  $proc = Get-Process -Id $_.ProcessID            
  $_ | Add-Member -MemberType NoteProperty -Name ProcessName -Value $($proc.ProcessName) -PassThru            
} |            
Format-Table DisplayName, ProcessName -GroupBy ProcessId

I’ve used Get-CimInstance in this example because of the CIM cmdlets are new to PowerShell v3. For a PowerShell v2 install use Get-WmiObject

Get-WmiObject -Class Win32_Service |             
sort ProcessID -Descending |            
foreach {            
  $proc = Get-Process -Id $_.ProcessID            
  $_ | Add-Member -MemberType NoteProperty -Name ProcessName -Value $($proc.ProcessName) -PassThru            
} |            
Format-Table DisplayName, ProcessName -GroupBy ProcessId

The WMI objects are piped through sort & into foreach where we add the process name. In both cases I’ve used Get-Process – either Get-CIMInstance or Get-WmiObject using the Win32_Process class could be used instead.

Format-table is used with GroupBy to produce a nicely formatted report. This information is important because it shows the services that are related to a particular process and the impact if that process fails..

March 3, 2012  6:04 AM

PowerShell v3 Updateable Help

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

One of the things that we have become used to in PowerShell v1 and v2 is the help files. They are installed with PowerShell, available on line and a graphical version is available for download. The online help files are updated over time but the local files aren’t.  This changes with PowerShell v3.

When you install PowerShell v3 (or install Windows 8/Windows Server 8 ) help files are not installed. Thats right you don’t get help files available. If you try using help you get this


PS> get-help get-process


    Get-Process [[-Name] <string[]>] [-ComputerName <string[]>] [-Module] [-FileVersionInfo]  [<CommonParameters>]

    Get-Process -Id <int[]> [-ComputerName <string[]>] [-Module] [-FileVersionInfo]  [<CommonParameters>]

    Get-Process -InputObject <Process[]> [-ComputerName <string[]>] [-Module] [-FileVersionInfo]  [<CommonParameters>]


    Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
        — To download and install Help files for the module that includes this cmdlet, use Update-Help.
        — To view the Help topic for this cmdlet online, type: "Get-Help Get-Process -Online" or
           go to


Using –full doesn’t bring more information and –examples doesn’t help either.

This may seem like a huge step backwards – how are we going to work without the local help files. I use them on a regular basis. Help. I want my help files back.

OK – what we get in PowerShell v3 is updateable help.  This means that you can pull the help files from the web and get them installed. Notice the Remarks section above about using Update-Help. The PowerShell core module has 3 cmdlets related to help

Save-Help  – downloads help files for later use via update-help
Update-Help – downloads and immediately updates help files

To use Save-help or Update-help you need to start PowerShell with elevated privileges (Run as administrator)


    Save-Help [-DestinationPath] <string[]> [[-Module] <string[]>] [[-UICulture] <string[]>] [-UseDefaultCredentials]
    [-Force]  [<CommonParameters>]

    Save-Help [[-Module] <string[]>] [[-UICulture] <string[]>] -LiteralPath <string[]> [-UseDefaultCredentials]
    [-Force]  [<CommonParameters>]

PS> get-help Update-Help


    Update-Help [[-Module] <string[]>] [[-SourcePath] <string[]>] [[-UICulture] <string[]>] [-Recurse]
    [-UseDefaultCredentials] [-Force]  [<CommonParameters>]

    Update-Help [[-Module] <string[]>] [[-UICulture] <string[]>] [-LiteralPath <string[]>] [-Recurse]
    [-UseDefaultCredentials] [-Force]  [<CommonParameters>]


Notice that we can update the help for individual modules

Lets pull down the help files first

Save-Help -DestinationPath c:\source\helpfiles -UICulture en-US -Force –Verbose

You will see a progress bar and messages like

VERBOSE: Your connection has been redirected to the following URI:
VERBOSE: Microsoft.PowerShell.Management: Saved
C:\source\helpfiles\Microsoft.PowerShell.Management_eefcb906-b326-4e99-9f54-8b4bb6ef3c6d_en-US_HelpContent.cab. Culture
en-US Version

for each help file that is downloaded.

the –Force parameter is interesting as it allows you to run a Save-Help or Update-Help command for the same module more than once each day.

I have found it is sometimes necessary to run save-help or update-help a couple of times to get all of the files downloaded

The help files can then be updated like this

Update-Help -SourcePath c:\source\helpfiles -UICulture en-US -Force –Verbose


You will get messages like this

VERBOSE: Microsoft.PowerShell.Management: Updated
C:\Windows\System32\WindowsPowerShell\v1.0\en-US\Microsoft.PowerShell.Commands.Management.dll-help.xml. Culture en-US


VERBOSE: Microsoft.PowerShell.Core: Updated
C:\Windows\System32\WindowsPowerShell\v1.0\en-US\about_WMI_Cmdlets.help.txt. Culture en-US Version



get-help Get-Process –full

will give you the help files you know and love

That is a two stage process but ahs the advantage that the help files can be pulled once and put on a network share for access by all systems. This is especially important for my servers where I don’t normally allow access to the Internet

The above tests were performed on PowerShell v3 on Windows 7 SP 1

The alternative is to update the help files directly

Update-Help  -UICulture en-US -Force –Verbose


Notice that in all cases I’ve given the UICulture – the help files come as a pair e.g.


You need to get the culture right to pull down the correct help files. I use English culture but I’m not sure what other localised versions are available  at this stage in the development cycle.

If you are running a 64 bit OS it looks like the help for 64 and 32 bit versions of PowerShell are updated simultaneously.

The help files may not be complete at this stage of Powershell v3 development so don’t be surprised if you don’t get help updates  for all modules – especially on Windows 8 server

March 2, 2012  4:29 PM

Windows 8 Modules

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

We saw the modules that come with Windows server 8


This is the list of modules available in a vanilla Windows 8 32 bit install


Again the core PowerShell modules are italicised – though that concept is becoming redundant as PowerShell v3 auto loads all modules it finds on the module path

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: