Test Whether Organizational Unit or Account Exists

Here are two quick functions which I have recently found useful. The first tests whether a user account exists. It takes the Domain and Identity as arguments. Using the “Stop” error action with Try/Catch keeps it from showing any errors. You can do this with any of the AD cmdlets, such as Get-ADOrganizationalUnit, Get-ADComputer and others. The first example tests for the existence of a user account:

This tests whether an OU exists:

About Alan

See http://www.akaplan.com/blog/about/
This entry was posted in Active Directory, PowerShell, Scripting and tagged , , . Bookmark the permalink.

Leave a Reply