- See more at: http://blogtimenow.com/blogging/automatically-redirect-blogger-blog-another-blog-website/#sthash.R8jFP7J2.dpuf Active Directory export for our Learning Management System ~ The musings of a Systems Admin

Friday 12 July 2013

Getting back to the AD Import and Export to our Learning Management System, after importing the Managers into AD I added the manager field to the export as seen below.

$Date = (Get-Date -format "dd-MM-yyyy")
if ( (Get-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin Quest.ActiveRoles.ADManagement
}

get-qaduser -SearchRoot 'domain.local/Users' -enabled -dontusedefaultincludedproperties -includedproperties sn,givenName,sAMAccountName,employeeNumber,telephoneNumber,mail,title,manager -SizeLimit 0 | sort-object | select-object sAMAccountName,employeeNumber,givenName,telephoneNumber,title,sn,mail,manager | export-csv -Delimiter ',' -NoTypeInformation -Path \\ServerX\LMS\LMS_export$Date.csv


Slight issue is that the 'manager' field in AD gives the container of the manager's account, LMS vendor can't work with that and wants the sAMAccountName for the manager.   Hmmmm, ok.
After some more poking around for a solution I came up with something that...
  • reads in the users from AD
  • adds a new null value property called 'ManagerSam' for each user
  • looks at each user and if the Manager field is not empty uses the Quest ActiveRoles tool 'get-qaduser' to lookup the sAMAccountName of the manager
  • assigns the sAMAccountName of the manager to our new 'ManagerSam' property
  • then takes all that and selects, sorts and exports to CSV
The following is what the script looks like...

$Date = (Get-Date -format "dd-MM-yyyy")
if ( (Get-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin Quest.ActiveRoles.ADManagement
}
$users = get-qaduser -SearchRoot 'domain.local/Users' -enabled -dontusedefaultincludedproperties -includedproperties sn,givenName,sAMAccountName,employeeNumber,telephoneNumber,mail,title,manager -SizeLimit 0
$users | Add-Member Noteproperty -Name ManagerSam -value $null
foreach ($user in $users){
    If ($user.Manager -ne $null){
        $user.ManagerSam = (get-qaduser -identity $user.Manager).samaccountname
        }
}
$users | select-object sAMAccountName,employeeNumber,givenName,telephoneNumber,title,sn,mail,managersam | sort-object sAMAccountName | export-csv -Delimiter ',' -NoTypeInformation -Path \\serverX\LMS\LMS_ad_export$Date.csv


Works like a charm and doesn't take forever to run.  More importantly it gives our LMS vendor what they need to have their software function correctly.  And that’s a fabulous thing!  :)

Steve

0 comments:

Post a Comment