Test if AD object/path exists

This Test-QADObject (Test-QADPath) function I have created gives a quick true or false answer on whether a specific user, computer, group, OU already exists in your domain.

Test-QADObject dsotniko

Test-QADObject 'OU=demo,DC=quest,DC=local'

Test-QADPath k*

I have posted the whole code with proper help and parameter handling to poshcode. Here’s a simplified one for the blog:

function Test-QADObject {
 param($Identity)
 
 (Get-QADObject $Identity -DontUseDefaultIncludedProperties `
  -WarningAction SilentlyContinue -ErrorAction SilentlyContinue `
  -SizeLimit 1) -ne $null
}

5 Responses to “Test if AD object/path exists”


  1. 1 dboftlp March 26, 2010 at 9:41 pm

    How can I use this function to help with the issue I’m working on? I posted this Q? on PowerGui.org

    http://powergui.org/thread.jspa?threadID=11701&tstart=0

    Thanks,
    -dboftlp

  2. 2 Rick Adams May 24, 2011 at 9:09 pm

    Dmitry,
    I am trying to use this snippet and running into issues. I am trying to test that OU’s, Access Templates, and Access Template Links all exist before running the script to onboard a new site ou structure. Using Test-QADObject to verify the Access Templates works great, both if they exist (returns True…) and if they don’t exist (returns False…). However, OU’s are not working. If an OU exists, it returns True, but if not, it errors out:

    Get-QADObject : Administration Service encountered an error when retrieving properties of the object
    ‘OU=Site2,OU=HubOU,DC=NET,DC=CORP,DC=COM’.
    Directory object not found. (Exception from HRESULT: 0x8007208D)

    At E:\Quest_Software_Project_Files\Scripts\OnboardNewSite\Test-Path.ps1:107 char:16
    + (Get-QADObject <<<< $Identity -DontUseDefaultIncludedProperties -WarningAction SilentlyContinue –
    ErrorAction SilentlyContinue -SizeLimit 1) -ne $null
    + CategoryInfo : NotSpecified: (:) [Get-QADObject], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Quest.ActiveRoles.ArsPower
    ShellSnapIn.Powershell.Cmdlets.GetGenericObjectCmdlet

    • 3 Dmitry Sotnikov May 25, 2011 at 12:46 am

      Rick,

      I think you are getting the exception because you have non-existent domain com.corp.net.

      Do you really need to test for that? Or just whether OU in the domain exists? In my experiments, if the domain is right – script works for OUs just fine.

      Dmitry


  1. 1 Dew Drop – March 23, 2010 | Alvin Ashcraft's Morning Dew Trackback on March 23, 2010 at 12:18 pm
  2. 2 AD News 3/26/2010 - The Experts Community Trackback on March 26, 2010 at 7:14 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




My Recent Tweets

Legal

The posts on this blog are provided “as is” with no warranties and confer no rights. The opinions expressed on this site are mine and mine alone, and do not necessarily represent those of my employer - WSO2 or anyone else for that matter. All trademarks acknowledged.

© 2007-2014 Dmitry Sotnikov

March 2010
M T W T F S S
« Feb   Apr »
1234567
891011121314
15161718192021
22232425262728
293031  

%d bloggers like this: