PoshCode Archive  Artifact [df0d4cffdb]

Artifact df0d4cffdbe4a6de2b9d8e277b18521142908deda86eacd857056b780cd7baaa:

  • File Get-User.ps1 — part of check-in [54dbd0b3fe] at 2018-06-10 13:15:04 on branch trunk — This function is an attempt to duplicate the Quest Get-QADUser cmdlet without using any third party snap-ins. If you want to run it against a Global Catalog you simply need to replace LDAP: with GC: and you will want to comment out the lines that pull the password last set and last logon timestamp unless you happen to be replicating those to your GC. (user: Jonathan Walz size: 1529)

# encoding: ascii
# api: powershell
# title: Get-User
# description: This function is an attempt to duplicate the Quest Get-QADUser cmdlet without using any third party snap-ins. If you want to run it against a Global Catalog you simply need to replace LDAP: with GC: and you will want to comment out the lines that pull the password last set and last logon timestamp unless you happen to be replicating those to your GC.
# version: 0.1
# type: function
# author: Jonathan Walz
# license: CC0
# function: Get-User
# x-poshcode-id: 2736
# x-archived: 2014-04-03T04:03:50
# x-published: 2014-06-15T04:05:00
#
#
function Get-User($user)
{
	# this function should be passed the CN of the user to be returned
	$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() 
	$root = [ADSI] "LDAP://$($dom.Name)"
	$searcher = New-Object System.DirectoryServices.DirectorySearcher $root
	$searcher.filter = "(&(objectCategory=person)(objectClass=user)(cn=$user))"
	$user = $searcher.FindOne()
	[System.Collections.Arraylist]$names = $user.Properties.PropertyNames
	[System.Collections.Arraylist]$props = $user.Properties.Values
	$userobj = New-Object System.Object
	for ($i = 0; $i -lt $names.Count)
		{
			$userobj | Add-Member -type NoteProperty -Name $($names[$i]) -Value $($props[$i])
			$i++
		}
	$userobj.pwdlastset = [System.DateTime]::FromFileTime($userobj.pwdlastset)
	$userobj.lastlogontimestamp = [System.DateTime]::FromFileTime($userobj.lastlogontimestamp)
	return $userobj
}