I guess I don't fully understand what you are asking, but here is a script that will spit out samaccountname based on a displayname input. I hardcoded my name in but you could take a name in as an argument/parameter (just uncomment the $args variable). I hope this helps.
$struser = "Kelley, Matthew" #$args[0] $ldapQuery = "(&(objectCategory=user))" $de = new-object system.directoryservices.directoryentry #$ads.pagesize=30000 $ads = new-object system.directoryservices.directorysearcher -argumentlist $de,$ldapQuery foreach($user in $struser) { $ads.Filter = "(&(objectClass=user)(displayname= $user))" $username = $ads.findone() ($username.properties).samaccountname } Matt From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On Behalf Of Kelley, Matthew Sent: Monday, July 29, 2013 4:21 PM To: powershell@lists.myitforum.com Subject: RE: [powershell] Ambiguous Identity Did you try to change this line to use the variable you set: From: -streetaddress $_.street -manager $_.manager ` To: -streetaddress $_.street -manager $manager ` From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On Behalf Of Candee Sent: Monday, July 29, 2013 4:03 PM To: powershell@lists.myitforum.com Subject: [powershell] Ambiguous Identity I'm not sure if I can do this, but I'm almost finished with these scripts for HR's new software package.... I need to update the "manager" attribute, but they are giving me the display name of the manager, not the samaccountname. I keep getting Ambiguous Identity, and I can't seem to get it. This is what I have: $manager = (get-qaduser displayname -eq $_.manager) I've tried it the other way as well , (get-qaduser $_.manager displayname), but that didn't work either. Can someone point me in the right direction? Thanks! Candee The entire script, for context: Import-Csv "C:\temp\filesin\user_changes.csv" |foreach{ #Check for preferred first name, if blank, use real first name $givenName = '' If( -not [string]::isnullorempty($_.preferredfirstname)) { $givenname = $_.preferredfirstname } else { $givenname = $_.firstname } #Check for preferred last name, if blank, use real last name $SN = '' If( -not [string]::isnullorempty($_.lastnamepreferred)) { $SN = $_.lastnamepreferred } else { $sn = $_.lastname } $manager = (get-qaduser displayname -eq $_.manager) $EMPNMR = $_.employeegui $SAM = $_.MISUSERNAME set-qaduser $SAM -displayname $displayname ` -givenname $givenname ` -sn $SN ` -company $_.Company ` -department $_.department -title $_.businesscardtitle -telephonenumber $_.telephone ` -city $_.city -postalcode $_.zip -state $_.state ` -streetaddress $_.street -manager $_.manager ` -oa @{ipphone=$_.ipphone;mobile=$_.mobile;employeenumber=$_.employeegui} ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ********************************************************** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ********************************************************** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1