powershell - Convert Distinguished Name to SamAccountName without Get-ADUser -


my machines have original build of powershell v2.0, get-aduser not work. trying convert manager property it's distinguishedname it's samaccountname.

$searcher = [adsisearcher]"(samaccountname=$env:username)" $searcher.findone().properties.manager 

this works if had get-aduser:

(get-aduser (get-aduser $user -properties manager).manager).samaccountname 

grabbed get-aduser statement here..

$ads_escapedmode_on = 2 $ads_settype_dn = 4 $ads_format_x500_dn = 7 $pathname = new-object -comobject "pathname" [void] $pathname.gettype().invokemember("escapedmode", "setproperty", $null, $pathname, $ads_escapedmode_on)  $searcher = [adsisearcher] "(samaccountname=$env:username)" $managerdn = $searcher.findone().properties["manager"] if ( $managerdn ) {   [void] $pathname.gettype().invokemember("set", "invokemethod", $null, $pathname, @($managerdn[0], $ads_settype_dn))   $escapeddn = $pathname.gettype().invokemember("retrieve", "invokemethod", $null, $pathname, $ads_format_x500_dn)   ([adsi] "ldap://$escapeddn").properties["samaccountname"][0] } 

get manager property current user (a distinguished name), escape using pathname object, bind using [adsi] type accelerator, , retrieve manager's samaccountname attribute.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -