Category Archives: PowerShell and Active Directory

Get an AD user’s manager

Interesting question on the forum about finding the manager for a given user in AD – assuming the Manager field is populated of course. If you’ve not worked with the AD cmdlets this is a good introduction to some of … Continue reading

Posted in PowerShell and Active Directory | 1 Comment

Comparing AD group membership on EmployeeId

Back in this post – http://itknowledgeexchange.techtarget.com/powershell/comparing-group-membership/ I showed how to compare the membership of two groups using Compare-Object. The comparison was based on the samAccountName. A question raised the issue of comparing AD group membership on EmployeeId In the case … Continue reading

Posted in PowerShell and Active Directory | 1 Comment

Get-ADUser filtering

Saw a question on the forums that revolved around Get-ADUser filtering. Initial code was like this Import-Csv .\users.txt | foreach {   Get-ADUser -Filter {Name -like $_.Name} } which on the face of it seems reasonable. However, you get errors like … Continue reading

Posted in PowerShell and Active Directory | Leave a comment

Are your domain controllers real?

A question on the forum asked about discovering if domain controllers are physical or virtual machines. This will do the job foreach ($domain in (Get-ADForest).domains) {   Get-ADDomainController -filter * -server $domain |   sort hostname  |   foreach { … Continue reading

Posted in PowerShell and Active Directory, PowerShell and CIM | Leave a comment

Name mismatch

Ever wondered why you can’t do this: Get-ADComputer -Filter * -SearchBase ‘OU=Servers,DC=Manticore,DC=org’ | Get-CimInstance -ClassName Win32_OperatingSystem The –ComputerName parameter on get-CimInstance accepts pipeline input BUT its by property name. PS> Get-Help Get-CimInstance -Parameter ComputerName -ComputerName [<String[]>]     Specifies computer on … Continue reading

Posted in PowerShell and Active Directory, PowerShell and CIM | Leave a comment

Modifying AD users in bulk

Modifying AD users in bulk involves either setting one or more properties to the same value for a set of users or reading in the values you need from a data source of some kind. We prepared some test data … Continue reading

Posted in PowerShell and Active Directory, Powershell Basics | Leave a comment

Test data for bulk AD changes

I’ve had a number of questions about changing AD user data in bulk. If you need to do that you need some test data. The specific questions were around setting the Division property and the EmployeeNumber at the same time … Continue reading

Posted in PowerShell and Active Directory, Powershell Basics | Leave a comment