PoshCode Archive  Artifact [f312974f61]

Artifact f312974f612ef0d258493fad858bea620db3e68742929ba188ee8a0db6e264f3:

  • File Test-QADObject.ps1 — part of check-in [2f2b8cd894] at 2018-06-10 13:00:22 on branch trunk — Check if the AD object/path exists. Accepts DN, SID, GUID, UPN, samAccountName, Name or Domain\Name. Returns $true or $false. (user: Dmitry Sotnikov size: 1709)

# encoding: ascii
# api: powershell
# title: Test-QADObject
# description: Check if the AD object/path exists. Accepts DN, SID, GUID, UPN, samAccountName, Name or Domain\Name. Returns $true or $false.
# version: 0.1
# type: script
# author: Dmitry Sotnikov
# license: CC0
# function: Test-QADObject
# x-poshcode-id: 1717
# x-archived: 2016-03-25T09:38:27
# x-published: 2010-03-22T08:28:00
#
# 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
#
<#
	.SYNOPSIS
		Quick way to see whether the object exists in AD.

	.DESCRIPTION
		Returns $true if at least one object matching the criteria exists and false otherwise.

	.PARAMETER  Identity
		Specify the DN, SID, GUID, UPN or Domain\Name of the directory object you want to find

	.EXAMPLE
		PS C:\> Test-QADObject dsotniko

	.EXAMPLE
		PS C:\> Test-QADObject 5ae7197e-cac3-42bf-9541-e06fa33ed965

	.EXAMPLE
		PS C:\> Test-QADObject 'OU=demo,DC=quest,DC=local'

 .INPUTS
		System.String,System.String[]

	.OUTPUTS
		System.Boolean

	.NOTES
		(c) Dmitry Sotnikov, http://dmitrysotnikov.wordpress.com
  Requires Quest AD cmdlets which are a free download from
  http://www.quest.com/activeroles-server/arms.aspx

	.LINK
		Get-QADObject

#>
function Test-QADObject {
	[CmdletBinding()]
	param(
		[Parameter(Position=0, Mandatory=$true)]
		[System.String]
		$Identity
	)
  (Get-QADObject $Identity -DontUseDefaultIncludedProperties `
    -WarningAction SilentlyContinue -ErrorAction SilentlyContinue `
    -SizeLimit 1) -ne $null
}

Set-Alias -Name Test-QADPath -Value Test-QADObject