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
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
Post a Comment