Monthly Archives: January 2013

List AD users in a group using powershell

This is not a rocket science thing since there are apparently multiple ways to do this but I had a specific requirement to quickly get a list of users for a group but only list specific properties which include the “Title” property that is not available using the AccountManagement namespace.

So without mush further ado… here is a simple script that works for me.

# Read the input parameters $GroupName
param([string] $GroupName = $(throw write-host "Please specify the group name." -Foregroundcolor Red))

$Recurse = $true

$OutputFile = "GroupUsers.csv"
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain
$group=[System.DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity($ct, $GroupName)
$members = $group.GetMembers($Recurse)

$columnNames = "Name,Title,Description"
$columnNames | Out-File -FilePath $OutputFile -Encoding 'UTF8'
foreach($user in $members){
    $DE = $user.GetUnderlyingObject()
    $output = $user.name + "," + $DE.title + "," + $user.description

    Write-Host $output
    $output | Out-File -FilePath $OutputFile -Encoding 'UTF8' -append
    $output = ""
}

In order to get to the ‘Title’ property I use the ‘GetUnderlyingObject’ method to get the DirectoryEntry object which do have the ‘Title’ property. This way it makes it possible to access any/all the ‘forgotten’ properties which they never implemented in the new namespace.
Additionally it also save the output to a CSV file.

2013 – the year after the end of the world

So we’ve survived the end of the world (Mayan calendar joke) and we’re stuck with ourselves… so to speak.

Some things to remember 2012 by (that I took interest in)

  • The Olympic games in London
  • People that passed away that I had respect for: Neil Armstrong, Ernest Borgnine, Patrick Moore, Whitney Houston
  • Riaan Cruywagen retired!
  • The end of the world… that didn’t happen!

What can we look forward to in this new year? Lets see

  • Windows 8/RT will be a spectacular… failure
  • Androids will take over (as long as they’re not paranoid)
  • Prices will go up… but at least the rain will come down (if any)
  • More politics and violence going nowhere
  • More strikes… over crap issues
  • I ran out of ideas.

On a personal front, my family will grow by one soon. That will probably keep us busy for the rest of the year. Also, I really hope to get going writing my books (Sci-Fi related)