PowerShell for Windows Admins

December 10, 2012  4:00 PM

Keep taking the tablets

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tablets seem to be all the rage at the moment. I’ve been working with three different types over the last month or so and thought I’d share my observations. These are base on my personal circumstances and needs – yours may be quite different.

The 3 tablets are in order that I started using them:

  • ipad 3
  • Kindle Fire HD
  • Microsoft Surface

The ipad is currently the iconoclastic tablet and has had masses written about. At the moment its the least useful of the tablets. I’ll explain why in a minute.

The Kindle Fire HD is relatively new and is a heavily customised versions of Android. Its a 7 inch device with a very nice email client that can access multiple accounts and a reasonably fast browser. Its size makes it small enough to use one handed as an e-reader. The other two being 1o inch tablets are really meant for two hands and are not as comfortable to use as e-readers. Being bigger they are more susceptible to glare on the screen. The smaller Kindle screen is easier to angle for glare avoidance.

You can synchronise files using the USB cable.

A simple Kindle is the best option if all you want is an e-reader – its small enough to slip in a pocket. Ideal for travelling. If you want a bit more the Fire is not much bigger and not that much more expensive.

The Surface is the youngest of the tablets. It runs the RT version of Windows 8 plus full versions of the Office products – Word, Excel & PowerPoint. Windows 8 enables the synchronisation of settings across multiple machines – I have a laptop, netbook and tablet running Windows 8 and a number of settings including IE favourites automatically sync. It also looks like wireless network settings sync!

The Surface cover folds down to give a keyboard. Its not something that I would want to use all day every day but with a touchpad mouse its more than adequate – I recently prepared a 2000 word article on it with no problems. The flip out stand on the back of the Surface props the screen at a good angle for use.

A full size USB port is a huge bonus for the Surface. It gives me options for mobile working – SkyDrive or USB. Covers all eventualities.

The Surface also includes PowerShell v3.  Just the console not ISE. Its a constrained version of PowerShell but it there.

By contrast the ipad has a usable app that functions as a mobile white board. That’s all I’ve really found useful.

Much is made of the numbers of apps available in the various app stores but if you actually look at them you have to wonder – how many versions of Sudoko do you really need?

Between the Kindle Fire and the Surface I have my leisure and business mobile needs met. The ipad doesn’t bring anything new to the table – that I need and so doesn’t get used.

As I said at the beginning these are my observations based on my needs and experiences. Yours may well be different.

December 10, 2012  2:25 PM

Get-CimClass changes

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

One thing that I don’t think I’ve mentioned is that the Get-CimClass output changed during the development process.

In PowerShell v3 RTM you can dig into a WMI class like this

Get-CimClass -ClassName Win32_OperatingSystem | select -ExpandProperty CimClassMethods
Get-CimClass -ClassName Win32_OperatingSystem | select -ExpandProperty CimClassProperties
Get-CimClass -ClassName Win32_OperatingSystem | select -ExpandProperty CimClassQualifiers
Get-CimClass -ClassName Win32_OperatingSystem | select -ExpandProperty CimSystemProperties

In at least some of the CTP versions of PowerShell v3 there were parallel, or alternate, properties you could use: Methods , Properties and Qualifiers respectively.

You may see reference to them in older posts – if you do just prefix with CimClass and you’ll be good.

December 9, 2012  1:10 PM

Reminder–PowerShell Jobs session

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Quick reminder that this coming Tuesday the UK PowerShell group presents a session on PowerShell Jobs

Details from


December 9, 2012  3:41 AM

Bulk modifications using Set-AdUser

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The standard approach to the bulk modification of users is to create a CSV file with an identifier and the data you want to change. Here’s part of a CSV file that could be used to modify some AD attributes – Division, City and Office

mgreen,Accounting,”Main Office”,”New York”
dgreen,Sales,”North East”,Boston
jgreen,Marketing,”North West”,Seattle

I always like to first test what is set

$users = Import-Csv -Path C:\Scripts\adtest.csv            
foreach ($user in $users) {            
 Get-ADUser -Identity $user.SamAccountName -Properties * |            
 select SamAccountName, Division, Office, City             

A simple loop through each user and display the data. I’ve used –Properties * to ensure that I get the data I want. I could have put the attribute names in to restrict the returned data – might be a good idea if you are working with lots if user accounts at once

SamAccountName      Division            Office              City
————–      ——–            ——              —-
jgreen                                  Test
bkent               AD Admin            ADML House          Peterborough

With Set-ADUser you get two options – a named parameter or the Add, Replace, Clear, Remove parameters.  See the help file for more details. All of our attributes have named parameters  so we can use this code

# Import AD Module             
Import-Module ActiveDirectory            
# Import CSV into variable $userscsv            
#$userscsv = import-csv D:\areile\Desktop\adtest.csv            
$users = Import-Csv -Path C:\Scripts\adtest.csv            
# Loop through CSV and update users if the exist in CVS file            
foreach ($user in $users) {            
#Search in specified OU and Update existing attributes            
 Get-ADUser -Filter "SamAccountName -eq '$($user.samaccountname)'" -Properties * -SearchBase "cn=Users,DC=manticore,DC=org" |            
  Set-ADUser -City $($user.City) -Office $($user.Office) -Division $($user.Division)            

Import the CSV file and loop through the users. For each user get the user object and pipe to Set-ADUser. The new attribute values are set from the CSV file data

Alternatively if you know the LDAP name of the attribute OR there isn’t a parameter for that attribute use the –Replace parameter.

# Import AD Module             
Import-Module ActiveDirectory            
# Import CSV into variable $userscsv            
#$userscsv = import-csv D:\areile\Desktop\adtest.csv            
$users = Import-Csv -Path C:\Scripts\adtest.csv            
# Loop through CSV and update users if the exist in CVS file            
foreach ($user in $users) {            
#Search in specified OU and Update existing attributes            
 Get-ADUser -Filter "SamAccountName -eq '$($user.samaccountname)'" -Properties * -SearchBase "cn=Users,DC=manticore,DC=org" |            
  Set-ADUser -Replace @{l = "$($user.City)"; physicalDeliveryOfficeName = "$($user.Office)"; division = "$($user.Division)"}            

The thing to note here is that the LDAP attribute names don’t always match the GUI names which are used as parameters. Get-ADUser seems to translate OK though!  You can find the correct name using ADSIEdit.

Note also that the help file for Set-AdUser is incorrect in at least once place – the list of attribute name-value pairs must be separated by semi-colons NOT commas as the help file states

December 7, 2012  11:28 AM

Amazon does PowerShell

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

A suite of PowerShell cmdlets for managing Amazon Web Services has been released


The cmdlets can be downloaded from


Information on using the cmdlets can also be found on this site

December 5, 2012  1:31 PM

Counting the members in an AD group

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

A question came up on the forum about counting the number of members a group has.  There are a number of ways of doing this but this is one of the easiest

$data = @()            
Get-ADGroup -Filter {Name -like "ADL*"} |            
foreach {            
 $data += New-Object -TypeName PSObject -Property @{            
   Name = $_.Name            
   MemberCount = (Get-ADGroupMember -Identity $($_.DistinguishedName) | Measure-Object ).Count            

Use the Get-ADGroupMember cmdlet and pipe the output to Measure-Object. Take the Count property.

BTW the forums I refer to are at powershell.org  If you haven’t visited I would strongly recommend you do.

December 3, 2012  4:58 PM

Comparing group membership

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

A question on the forum asked about comparing the memberships of two groups & displaying information about the users that are in both. The normal reaction is that you have to iterate through the two groups but then I remembered Compare-Object and came up with this

$group1 = Get-ADGroupMember -Identity ADL-group1 | select SamAccountName            
$group2 = Get-ADGroupMember -Identity ADL-group2 | select SamAccountName            
Compare-Object -ReferenceObject $group1 -DifferenceObject $group2 -IncludeEqual |             
where SideIndicator -eq "==" |            
foreach {            
 $sam = ($_.InputObject).SamAccountName             
 Get-ADUser -Identity $sam -Properties *            

Get the group membership of each group into a variable – I’m using the Microsoft cmdlets and just selecting the samaccountname to compare.

Using Compare-Object I used the –IncludeEqual parameter to make sure I got the matches and then filtered on the SideIndicator value of “==” .  That gets me the matches.

I then loop through them and use Get-ADUser to pull back the properties I need.

If you want to do this with the quest cmdlets use distinguished name instead of samaccountname

December 3, 2012  3:02 PM

How to give yourself an ulcer in one evening or why Word remains minimised on the Taskbar

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I have just spent an extremely frustrating 3 hours trying to figure out why Word 2013 remained minimised on the task bar of my Windows 8 machine. Everything else opened up correctly including other Office applications such as Excel and PowerPoint.

I checked on other machines and it wasn’t the document I was trying to open – later found it was all Word documents – even those coming from my Skydrive.

Tried repairing Office – didn’t work

Looked through the registry – nothing

Tried opening Word through PowerShell – still minimised. Looked through the Word object – nothing.

Tried Internet searches – best option is to maximise through Task Manager – didn’t work. Tried move and size options – nothing.

Just had a brain wave. Yesterday I had an external monitor attached. Switched that on and there is Word in all its glory. Dragged the Window back to my laptop screen and everything works properly now.

So the moral of the story is don’t shut down word on an external monitor unless you want to give yourself an ulcer!

December 2, 2012  7:36 AM

PowerShell–jobs and scheduled tasks–date change

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I’ve had to move the Live Meeting to Tuesday 11 December

When: Tuesday, Dec 11, 2012 7:30 PM (GMT)



PowerShell jobs provide the ability to perform long running background tasks. With the introduction of cmdlets to schedule tasks the possibilities increase


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: KRSN4M
    Entry Code: s`xS<XHp2
    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.

December 2, 2012  5:39 AM

Defining Active Directory Identity with PowerShell

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

There are two sets of cmdlets for working with Active Directory – Microsoft and Quest. Unfortunately they offer slightly different options for defining the identity of the user you want to work with.

The Microsoft cmdlets offer these options:

Distinguished Name = "CN=GREEN Mike,CN=Users,DC=Manticore,DC=org"
GUID  = 53837835-1de0-4686-ae3f-b8cf23890ce3
Sid = S-1-5-21-3881460461-1879668979-35955009-6273
sAMAccountName = mgreen

By contrast the Quest cmdlets offer these options for defining Identity:

DN = DistinguishedName = "CN=GREEN Mike,CN=Users,DC=Manticore,DC=org"
SID = S-1-5-21-3881460461-1879668979-35955009-6273
GUID = 53837835-1de0-4686-ae3f-b8cf23890ce3
UPN = UserPrincipalName = mgreen@manticore.org
Domain\UserName = MANTICORE\mgreen

If you not using the cmdlets and relying on the ADSI interface – all you can use is the distinguished name

$user = [ADSI]”LDAP://CN=GREEN Mike,CN=Users,DC=Manticore,DC=org"

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: