PowerShell for Windows Admins

June 23, 2011  3:16 PM

root\wmi – Monitor brightness

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The monitor brightness can be discovered like this

function get-monitorBrightness {

$monitors = Get-WmiObject -Namespace root\wmi -Class WmiMonitorBrightness

foreach ($monitor in $monitors){
  $brightness = New-Object -TypeName PSObject -Property @{
        CurrentLevel = $monitor.CurrentBrightness
        MaxLevel = $($monitor.Level | sort | select -Last 1)


The WmiMonitorBrightness class is used. The level property holds the brightness levels that can be set. A simple sort ensures we get the maximum setting

June 23, 2011  12:46 PM

Testing the 4K boundary

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Advanced Format disks have started shipping –see http://managedux.com/2011/04/26/using-vbscript-to-check-partitions-for-advanced-format-4k-512e-sector-alignment/

These disks use a 4096 byte sector instead of 512. To get the best performance from these disks the partitions have to be aligned to a 4K boundary. This happens automatically in Windows 2008 and above. 

We need to be able to start testing partition alignment. This function uses a couple of WMI classes to do just that.

function test-4KAligned {
param (

$partitions = Get-WmiObject -Class Win32_DiskPartition -ComputerName $computer

foreach ($partition in $partitions){
  $query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID=’$($partition.DeviceID)’} WHERE AssocClass=Win32_LogicalDiskToPartition"
  $disktopart = Get-WmiObject -ComputerName $computer -Query $query
if (($partion.StartingOffset % 4096) -eq 0){
   $align = $true
else {
   $align = $false
$diskpartition = New-Object -TypeName PSObject -Property @{
   Partition = $partition.Name
   Description = $partition.Description
   AlignedTo4Kboundary = $align
   Drive = $disktopart.DeviceID
if ($drive) {
   if ($drive -eq $diskpartition.Drive){$diskpartition}
else {$diskpartition}


Tests disk partition alignment to 4k boundary

Tests disk partition alignment to 4k boundary.

Default is that all drives are tested

.PARAMETER  computer
Computer to test

Drive to test


Tests local machine

test-4kaligned -computer server01

Tests remote machine

test-4kaligned -computer server01 -drive C:

Tests C: drive on remote machine



The test is performed using modulus arithmetic on the starting offset. A result of zero means its divisible exactly by 4096 so is aligned.

June 21, 2011  2:40 PM

Rescheduled UG meeting

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Apologies for rescheduling with no notice but my broadband router failed tonight.

When: Thursday, Jun 30, 2011 7:30 PM (BST)

Where: Live Meeting


Re-scheduled – using PowerShell to automate Office including Word, Excel, OneNote, Visio and Access


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: WNGBC8
    Entry Code: k&w2kpF8d
    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 21, 2011  2:09 PM

PowerShell UK user group: apologies

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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

Richard Siddaway Richard Siddaway Profile: 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

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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.

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: