String or Script that Outputs Parent of System's OU


hey guys - 

i'm needing set condition systems within sccm set variable based on parent of system's ou.  an example below:

for system dn: ldap://cn=system1,ou=workstations,ou=nashville,ou=tennessee,dc=company,dc=abc,dc=com

i'd want output be: nashville

i wrote script did on workstation, when trying on win7 x64 workstations didn't have newer version of powershell, had errors.  below script followed error received.  (i call value mainou)

script

#get main ou
function get-ou
{
    $dn = ([adsisearcher]"(&(name=$env:computername)(objectclass=computer))").findall().path
    $ouname = ($dn.split(","))[2]
    $oumainname = $ouname.substring($ouname.indexof("=")+1)
}
$oumainname

error (on win7x64 systems)

method invocation failed because [system.directoryservices.propertyvaluecollection] doesn't contain method named 'split'.
@ c:\mainou.ps1:14 char:40
+     $ouname = ($distinguishedname.split <<<< (","))[2]
    + categoryinfo          : invalidoperation: (split:string) [], runtimeexception
    + fullyqualifiederrorid : methodnotfound
 
cannot call method on null-valued expression.
@ c:\mainou.ps1:15 char:52
+     $oumainname = $ouname.substring($ouname.indexof <<<< ("=")+1)
    + categoryinfo          : invalidoperation: (indexof:string) [], runtimeexception
    + fullyqualifiederrorid : invokemethodonnull

any idea how can work?  thanks!


ben k.

change findall() findone() , should work.

also, technically parent of example object ou=workstations. guess want grandparent.


richard mueller - mvp enterprise mobility (identity , access)



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file