PowerShell for Windows Admins:

Active Directory


August 9, 2017  4:59 AM

Get-ADUser filtering

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Active Directory, Powershell

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 this Get-ADUser : Property: 'Name'...

May 9, 2017  3:23 AM

Are your domain controllers real?

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Active Directory, CIM, Powershell

A question on the forum asked about discovering if domain controllers are physical or virtual machines. In other words Are your domain controllers real? This will do the job:

foreach ($domain in (Get-ADForest).domains) {
 Get-ADDomainController -filter * -server $domain |
 sort hostname...


March 29, 2017  1:29 PM

Name mismatch

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Active Directory, CIM, Powershell

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...


March 4, 2017  5:59 AM

Modifying AD users in bulk

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Active Directory, Powershell

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 in the last post so lets see how we use it.

$users = Import-Csv -Path...


March 3, 2017  1:52 PM

Test data for bulk AD changes

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Active Directory, Powershell

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 – but some accounts didn’t have an employee number. First you need...


February 16, 2017  2:24 PM

Get-ADUser doesn’t display all properties

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Active Directory, Powershell

Microsoft’s Active Directory cmdlets have some issues. One of the ones that catches everyone when they start using them is that Get-ADUser doesn’t display all properties. A default call to Get-ADUser displays a subset of the available properties of the user object:

DistinguishedName :...


December 14, 2016  5:38 AM

Active Directory Schema Versions

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Active Directory, Powershell

With the release of Windows Server 2016 its time to update my schema versions script

$sch = [System.DirectoryServices.ActiveDirectory.ActiveDirectorySchema]::GetCurrentSchema()
$de = $sch.GetDirectoryEntry()
switch ($de.ObjectVersion) {
    13{"{0,25} " -f "Schema Version...


November 18, 2016  5:14 AM

Changing the samAccountName

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Active Directory, Powershell

I was recently asked how the samAccountName – also referred to as the login id – could be changed. First lets look at an account: PS C:\Scripts> Get-ADUser -Identity 'FredFox' DistinguishedName : CN=FOX...


November 17, 2016  8:18 AM

Creating test accounts in Active Directory

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Active Directory, Powershell

There’s often a need to create test accounts in AD. You may want to create a a set of test accounts or if you have a demo/test lab you may need accounts in that. Creating the names for the accounts is a pain unless you go down the test1, test2 etc route. One way to real looking names is I use...


November 5, 2016  10:59 AM

Creating a new AD forest

Richard Siddaway Richard Siddaway Profile: Richard Siddaway
Active Directory, Powershell, Windows Server 2016

As I’ve completely rebuilt my demo/lab machine I need to re-create the Active Directory This is now so simple even on a server core machine First install the roles and features needed Add-WindowsFeature -Name AD-Domain-Services, RSAT-AD-PowerShell, DNS, RSAT-DNS-Server, DHCP,...


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: