PoshCode Logo PowerShell Code Repository

Test-QADObject by Dmitry Sotnikov 22 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1717"></script>download | new post

Check if the AD object/path exists. Accepts DN, SID, GUID, UPN, samAccountName, Name or Domain\Name. Returns $true or $false.
Requires Quest AD cmdlets which are a free download from http://www.quest.com/activeroles-server/arms.aspx.
(c) Dmitry Sotnikov, http://dmitrysotnikov.wordpress.com

  1. <#
  2.         .SYNOPSIS
  3.                 Quick way to see whether the object exists in AD.
  4.  
  5.         .DESCRIPTION
  6.                 Returns $true if at least one object matching the criteria exists and false otherwise.
  7.  
  8.         .PARAMETER  Identity
  9.                 Specify the DN, SID, GUID, UPN or Domain\Name of the directory object you want to find
  10.  
  11.         .EXAMPLE
  12.                 PS C:\> Test-QADObject dsotniko
  13.  
  14.         .EXAMPLE
  15.                 PS C:\> Test-QADObject 5ae7197e-cac3-42bf-9541-e06fa33ed965
  16.  
  17.         .EXAMPLE
  18.                 PS C:\> Test-QADObject 'OU=demo,DC=quest,DC=local'
  19.  
  20.  .INPUTS
  21.                 System.String,System.String[]
  22.  
  23.         .OUTPUTS
  24.                 System.Boolean
  25.  
  26.         .NOTES
  27.                 (c) Dmitry Sotnikov, http://dmitrysotnikov.wordpress.com
  28.   Requires Quest AD cmdlets which are a free download from
  29.   http://www.quest.com/activeroles-server/arms.aspx
  30.  
  31.         .LINK
  32.                 Get-QADObject
  33.  
  34. #>
  35. function Test-QADObject {
  36.         [CmdletBinding()]
  37.         param(
  38.                 [Parameter(Position=0, Mandatory=$true)]
  39.                 [System.String]
  40.                 $Identity
  41.         )
  42.   (Get-QADObject $Identity -DontUseDefaultIncludedProperties `
  43.     -WarningAction SilentlyContinue -ErrorAction SilentlyContinue `
  44.     -SizeLimit 1) -ne $null
  45. }
  46.  
  47. Set-Alias -Name Test-QADPath -Value Test-QADObject

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me