Thursday 8 May 2014

Powershell to find User details from AD

Seen a computername hitting your databases not sure who it is.  This will help you find the owner information of the computer.  Enter the PC name, and it will show the details stored in AD under owner.

$strResponse

= "Quit"

do

{

$machine

= Read-Host "Please supply computer to lookup"

$strFilter

= "(&(objectCategory=Computer)(name="+$machine+"))"

$objDomain

= New-Object System.DirectoryServices.DirectoryEntry

$objSearcher

= New-Object System.DirectoryServices.DirectorySearcher

$objSearcher

.SearchRoot = $objDomain

$objSearcher

.PageSize = 1000

$objSearcher

.Filter = $strFilter

$objSearcher

.SearchScope = "Subtree"

$colProplist

= "name", "description"

foreach

($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults

= $objSearcher.FindAll()

foreach

($objResult in $colResults)

{
$objItem = $objResult.Properties; $objItem.name; $objItem.description}

 


$strResponse

= Read-Host "Are you sure you want to quit application? (Y/N)"}


until ($strResponse -eq "Y")

No comments:

Post a Comment

Your views:-