Retreive an AD object GUID to a string, NO Quest cmdlest


hello;

i trying retreive computer's guid string.

$computerdescription = @{}
$computerou = @{}
$computerguid = @{}
$results = @()
$strcategory = "computer"
$stros = "windows*server*"
$domainname = 'ldap://ou=ent,dc=state,dc=mt,dc=ads'
$root = new-object directoryservices.directoryentry $domainname
$objsearcher = new-object directoryservices.directorysearcher
$objsearcher.searchroot = $root
$objsearcher.searchscope = "subtree"
$objsearcher.filter =  "(&(&(objectcategory=computer)(operatingsystem=windows*server*))(name=server*))"
$colresults = $objsearcher.findall()
foreach ($objresult in $colresults)
{
$objcomputer = $objresult.properties #; $objcomputer.name#; $objcomputer.description
$computerdescription.add([string]$objcomputer.name, [string]$objcomputer.description)
$length = $objcomputer.item("distinguishedname")[0].split(",").length
$ou = $objcomputer.item("distinguishedname")[0].split(",")[$length - 5].split("=")[1]
$computerou.add([string]$objcomputer.name, $ou)
$computerguid.add([string]$objcomputer.name, $objcomputer.objectguid)
}

in case, $computerguid values bytearray[] types.

if convert $computerguid["server01"].tostring() get
system.directoryservices.resultpropertyvaluecollection

how can valid guid?

karl

i figured out:

foreach ($objresult in $colresults)
{
$computer = $objresult.getdirectoryentry()
$computer = $objresult.getdirectoryentry()
$computerdescription.add([string]$computer.name, [string]$computer.description)
$length = >$computer.distinguishedname.tostring().split(",").length
$ou = >$computer.distinguishedname.tostring().split(",")[$length - 5].split("=")[1]
$computerou.add([string]$computer.name, $ou)
$computerguid.add([string]$computer.name, $computer.psbase.guid.tostring())
}

karl


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Windows 2016 RDS event 1306 Connection Broker Client failed to redirect the user... Error: NULL