PowerShell for Windows Admins

June 21, 2011  2:09 PM

PowerShell UK user group: apologies

Posted by: Richard Siddaway
PowerShell, User Group

My apologies to anyone who tried to connect to the PowerShell UK UG Live Meeting tonight. My broadband router stopped working, permanently, today and I didn’t find out until I got home from work.

By the time I’d tracked down the problem, installed and configured a new router it was well past the meeting finish time.

Apologies for an unavoidable problem.

I’ll re-schedule the meeting for next week.

June 18, 2011  4:06 AM

PowerShell resources: Tip of the Day

Posted by: Richard Siddaway
PowerShell v2

Have a look at the RSS feed available from http://powershell.com/cs/blogs/tips/

There are some good ideas in the tips and if nothing else it will get you thinking about PowerShell

June 17, 2011  12:38 PM

PowerShell User group–topics

Posted by: Richard Siddaway
PowerShell, User Group

I’m starting to think about next years programme for the UK user group.

Are there any topics – IT Pro or Dev orientated that you would like to see?

Any speakers you would like me to try and get back?

Do you want more introductory level sessions to cover the basics, high level sessions or the usual mixture?

The sessions will be over Live Meeting still dues to restrictions on facilities


Please reply by leaving a comment on this blog post


Thank you

June 16, 2011  1:26 PM

root\wmi – WmiMonitorColorCharacteristics

Posted by: Richard Siddaway
Hardware, PowerShell v2

The rather long winded name of this class might put you off but it does show something useful

Get-WmiObject -Namespace root\wmi -Class WmiMonitorColorCharacteristics

produces these results (dropping the system properties)

Active           : True
Blue             : System.Management.ManagementBaseObject
DefaultWhite     : System.Management.ManagementBaseObject
Green            : System.Management.ManagementBaseObject
InstanceName     : DISPLAY\LGD6301\5&21e3487a&0&UID33554704_0
Red              : System.Management.ManagementBaseObject

As we have to drill down into these other objects we will create a function

function get-monitorColourCharacteristics {

$monitor = Get-WmiObject -Namespace root\wmi -Class WmiMonitorColorCharacteristics

$colours = New-Object -TypeName PSObject -Property @{
  Monitor = $monitor.InstanceName
  Active = $monitor.Active
$colours |
Add-Member -MemberType NoteProperty -Name "White XY" -Value @($monitor.DefaultWhite.X, $monitor.DefaultWhite.Y ) -PassThru |
Add-Member -MemberType NoteProperty -Name "Red XY" -Value @($monitor.Red.X, $monitor.Red.Y ) -PassThru |
Add-Member -MemberType NoteProperty -Name "Green XY" -Value @($monitor.Green.X, $monitor.Green.Y ) -PassThru |
Add-Member -MemberType NoteProperty -Name "Blue XY" -Value @($monitor.Blue.X, $monitor.Blue.Y )



The XY values are explained in these articles



June 16, 2011  11:03 AM

New MEAP release for PowerShell and WMI

Posted by: Richard Siddaway
Books, PowerShell v2, WMI

Chapters 10 and 11 have been added to the PowerShell and WMI early access release – www.manning.com/siddaway2

Chapter 10 is about printers and it covers:

  • discovering printer configurations;
  • testing printer status;
  • discovering and comparing printer drivers;
  • managing printers;
  • administering print jobs; and
  • testing printers.

Chapter 11 dives into the details of networking:

  • discovering network adapters and their configuration;
  • discovering active protocols;
  • configuring static IP addresses and other TCP/IP settings;
  • enabling DHCP on the adapter;
  • managing DNS and WINS settings in the TCP/IP properties; and
  • displaying the IPv4 routing table.

The code for these and all earlier chapters is available for download.
What’s Next?
In Chapter 12, we will look at managing IIS.

June 15, 2011  12:53 PM

root\wmi–Monitor information

Posted by: Richard Siddaway

Continuing our intermittent browse through the root\wmi namespace we find a set of classes that seem to be linked to monitors

Get-WmiObject -Namespace root\wmi -List WmiMonitor*



WmiMonitorBasicDisplayParams   seems like a good place to start

Get-WmiObject -Namespace root\wmi -Class WmiMonitorBasicDisplayParams


Active                        : True
DisplayTransferCharacteristic : 120
InstanceName                  : DISPLAY\LGD6301\5&21e3487a&0&UID33554704_0
MaxHorizontalImageSize        : 34
MaxVerticalImageSize          : 19
SupportedDisplayFeatures      : System.Management.ManagementBaseObject
VideoInputType                : 1


The supporteddisplayfeatures we need to dig into a bit

$monitor = Get-WmiObject -Namespace root\wmi -Class WmiMonitorBasicDisplayParams

ActiveOffSupported     : False
DisplayType            : 1
GTFSupported           : False
HasPreferredTimingMode : True
sRGBSupported          : False
StandbySupported       : False
SuspendSupported       : False


For interest sake the screen resolution of this monitor is 1366 x 768

We can calculate the approximate monitor size – which is the diagonal size – the max horizontal and vertical image sizes are truncated to the nearest centimeter. I think in inches so I want to convert

function get-monitorsize {
Get-WmiObject -Namespace root\wmi -Class WmiMonitorBasicDisplayParams |
select  @{N="Computer"; E={$_.__SERVER}},
@{N="Horizonal"; E={[System.Math]::Round(($_.MaxHorizontalImageSize/2.54), 2)}},
@{N="Vertical"; E={[System.Math]::Round(($_.MaxVerticalImageSize/2.54), 2)}},
E={[System.Math]::Round(([System.Math]::Sqrt([System.Math]::Pow($_.MaxHorizontalImageSize, 2) `
+ [System.Math]::Pow($_.MaxVerticalImageSize, 2))/2.54),2)}}

A little bit of pythagoras theorem and division by 2.54 gives me results I can understand.

June 14, 2011  11:12 AM

Scripting Guy Blog- PowerShell and WMI

Posted by: Richard Siddaway
Books, PowerShell v2, WMI

The Scripting Guy is running a series of posts this week featuring articles taken from PowerShell books published by Manning (www.manning.com). Yesterday was Don Jones’ PowerShell Lunches, today is my PowerShell and WMI

Read the articles and get the code for a substantial reduction in the price of the books

See http://blogs.technet.com/b/heyscriptingguy/archive/2011/06/14/use-powershell-to-simplify-access-to-wmi-data.aspx

for the article.

June 13, 2011  3:06 PM

Calculated Fields

Posted by: Richard Siddaway
PowerShell v2

You have probably seen something like this many times

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" |
select @{Name="FreeSpace";Expression={$_.Freespace / 1GB}}

We take an object and perform a calculation to in effect make a new property – a calculated field. Label can be used instead of Name if desired in PowerShell 2

This can also be done in Format-Table

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" |
Format-Table @{Name="FreeSpace";Expression={$_.Freespace / 1GB}}

There some other parameters we can use

We can control the alignment in the field

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" |
Format-Table @{Name="FreeSpace";Expression={$_.Freespace / 1GB}; Alignment="Left"}

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" |
Format-Table @{Name="FreeSpace";Expression={$_.Freespace / 1GB}; Alignment="Center"}

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" |
Format-Table @{Name="FreeSpace";Expression={$_.Freespace / 1GB}; Alignment="Right"}

We can format the string

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" |
Format-Table @{Name="FreeSpace";Expression={$_.Freespace / 1GB}; Format="F2"; Alignment="Left"}

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" |
Format-Table @{Name="FreeSpace";Expression={$_.Freespace / 1GB}; Format="F2"; Alignment="Center"}

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" |
Format-Table @{Name="FreeSpace";Expression={$_.Freespace / 1GB}; Format="F2"; Alignment="Right"}

And we can control the width of the string

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" |
Format-Table @{Name="FreeSpace";Expression={$_.Freespace / 1GB}; Width=11; Format="F2"; Alignment="Left"}

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" |
Format-Table @{Name="FreeSpace";Expression={$_.Freespace / 1GB}; Width=11; Format="F2"; Alignment="Center"}

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" |
Format-Table @{Name="FreeSpace";Expression={$_.Freespace / 1GB}; Width=11; Format="F2"; Alignment="Right"}


Width, format and alignment don’t work with select-object

June 12, 2011  1:45 PM

PowerShell User Group–21 June 2011

Posted by: Richard Siddaway
PowerShell, User Group

When: Tuesday, Jun 21, 2011 7:30 PM (BST)

Where: Virtual


Session will look at using PowerShell to automate Microsoft Office – Word, Excel, Visio, Access and more


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: Z7FFBT
    Entry Code: TC%f8)D(2
    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.

June 9, 2011  3:14 PM

Date Formats–custom formats

Posted by: Richard Siddaway
PowerShell v2

I’ve added examples of practically all of the custom elements that can be used in a date format

"d ShortDatePattern                                                :  {0} " -f (get-date -Format d )
"D LongDatePattern                                                 :  {0} " -f (get-date -Format D )
"f Full date and time (long date and short time)                   :  {0} " -f (get-date -Format f )
"F FullDateTimePattern (long date and long time)                   :  {0} " -f (get-date -Format F )
"g General (short date and short time)                             :  {0} " -f (get-date -Format g )
"G General (short date and long time)                              :  {0} " -f (get-date -Format G )
"m MonthDayPattern                                                 :  {0} " -f (get-date -Format m )
"M MonthDayPattern                                                 :  {0} " -f (get-date -Format M )
"o Round-trip date/time pattern always uses the invariant culture  :  {0} " -f (get-date -Format o )
"O Round-trip date/time pattern always uses the invariant culture  :  {0} " -f (get-date -Format O )
"r RFC1123Pattern always uses the invariant culture                :  {0} " -f (get-date -Format r )
"R RFC1123Pattern always uses the invariant culture                :  {0} " -f (get-date -Format R )
"s SortableDateTimePattern always uses the invariant culture       :  {0} " -f (get-date -Format s )
"t ShortTimePattern                                                :  {0} " -f (get-date -Format t )
"T LongTimePattern                                                 :  {0} " -f (get-date -Format T )
"u UniversalSortableDateTimePattern                                :  {0} " -f (get-date -Format u )
"U Full date and time – universal time                             :  {0} " -f (get-date -Format u )
"y YearMonthPattern                                                :  {0} " -f (get-date -Format y )
"Y YearMonthPattern                                                :  {0} " -f (get-date -Format Y )

"`nCustom Formats"
"d/M/y                                  :  {0} " -f (get-date -Format d/M/y )
"%d/%M/yy                               :  {0} " -f (get-date -Format d/M/yy )
"dd/MM/yyyy                             :  {0} " -f (get-date -Format dd/MM/yyyyy )
"dd/MM/yyyy %g                          :  {0} " -f (get-date -Format ‘dd/MM/yyyyy %g’)
"dd/MM/yyyy gg                          :  {0} " -f (get-date -Format ‘dd/MM/yyyyy gg’)
"dddd dd/MM/yyyy gg                     :  {0} " -f (get-date -Format ‘dddd dd/MM/yyyyy gg’)
"dddd dd/MM/yyyy %h:m:s tt gg           :  {0} " -f (get-date -Format ‘dddd dd/MM/yyyyy %h:m:s tt gg’)
"dddd dd/MM/yyyy hh:mm:s tt gg          :  {0} " -f (get-date -Format ‘dddd dd/MM/yyyyy hh:mm:s tt gg’)
"dddd dd/MM/yyyy HH:mm:s gg             :  {0} " -f (get-date -Format ‘dddd dd/MM/yyyyy HH:mm:s gg’)
"dddd dd/MM/yyyy HH:mm:s.ffff gg        :  {0} " -f (get-date -Format ‘dddd dd/MM/yyyyy HH:mm:s.ffff gg’)
"dddd dd MMM yyyy HH:mm:s.ffff gg       :  {0} " -f (get-date -Format ‘dddd dd MMM yyyyy HH:mm:s.ffff gg’)
"dddd dd MMMM yyyy HH:mm:s.ffff gg      :  {0} " -f (get-date -Format ‘dddd dd MMMM yyyyy HH:mm:s.ffff gg’)
"dddd dd MMMM yyyy HH:mm:s.ffff zz gg   :  {0} " -f (get-date -Format ‘dddd dd MMMM yyyyy HH:mm:s.ffff zz gg’)
"dddd dd MMMM yyyy HH:mm:s.ffff zzz gg  :  {0} " -f (get-date -Format ‘dddd dd MMMM yyyyy HH:mm:s.ffff zzz gg’)

The various custom elements can be combined in numerous other ways but these examples should show you how they all work.

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: