header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Piping properties from Get-QADuser to Set-Qaduser
Last Post 12 Jan 2010 08:59 AM by cameronove. 6 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
uSlackrUser is Offline
New Member
New Member
Posts:68
Avatar

--
07 Jan 2010 02:25 PM
    (Excuse me for being 2-3 years behind the PS curve :-) )
    I'm trying to fix our missing UPNs.  I wrote this to locate them:

    get-qaduser -includedproperties userprincipalname -SearchRoot "company.com/user accounts" -sizelimit 0|where {!($_.userprincipalname -like "*@*") }

    Which works great.  Now I want to pipe the output to set-qaduser to populate the UPN by adding this to the above code:

    |set-qaduser  -userprincipalname "$($_.samAccountName)@company.com"

    No matter what I try $_.samaccountname is always null.  What am I missing?

    \\Greg
    \\uSlackr
    PoshoholicUser is Offline
    PowerShell MVP, Community Director
    Basic Member
    Basic Member
    Posts:110
    Avatar

    --
    07 Jan 2010 05:56 PM
    The problem with your current script is that $_ doesn't have a value when you are trying to reference it. $_ only gets set inside script blocks in the pipeline like in ForEach-Object, Where-Object, or in Script Block parameters.

    So you need to either do this:

    ... | Set-QADUser -UserPrincipalName {"$($_.samAccountName)@company.com"}

    or this:

    ... | ForEach-Object {
    $_ | Set-QADUser -UserPrincipalName "$($_.samAccountName)@company.com"
    }
    Kirk Munro [MVP]
    Poshoholic

    My blog: http://poshoholic.com
    Follow me on Twitter: http://twitter.com/poshoholic
    uSlackrUser is Offline
    New Member
    New Member
    Posts:68
    Avatar

    --
    08 Jan 2010 05:33 AM
    Thanks, Kirk. The first option didn't appear to work but the second did!

    Thanks

    \\Greg
    \\uSlackr
    cameronoveUser is Offline
    Basic Member
    Basic Member
    Posts:332
    Avatar

    --
    12 Jan 2010 08:01 AM
    You could try this--the ldap search should be a lot faster than the where filter:

    get-qaduser -includedproperties userprincipalname,samaccountname -SearchRoot "company.com/user accounts" -ldapfilter '(!(userprincipalname=*@*))' -sizelimit 0 | %{$_.userprincipalname = "$($_.samaccountname)@company.com";$_.commitchanges()}

    Leave off the pipe to the foreach script block to see what that returns. When you're comfortable with the results then add the pipe to the foreach script block to make the changes.

    uSlackrUser is Offline
    New Member
    New Member
    Posts:68
    Avatar

    --
    12 Jan 2010 08:12 AM
    Cameron, this looks interesting. What type of object is being passed in $_? Is it an [ADSI] object that you are acting on directly instead of using Set-Qaduser?

    \\Greg
    \\uSlackr
    cameronoveUser is Offline
    Basic Member
    Basic Member
    Posts:332
    Avatar

    --
    12 Jan 2010 08:56 AM
    It's passing a user object from the get-qaduser cmdlet. It will have available all default properties as well as properties specified by the -includedproperties parameter. For you to actually change the parameters you will need to run PowerShell from an administrators context (loging as admin or runas admin) or pass a PSCredential object with admin credentials to the cmdlet.
    cameronoveUser is Offline
    Basic Member
    Basic Member
    Posts:332
    Avatar

    --
    12 Jan 2010 08:59 AM
    I'm not sure what the underlying technology Quest is relying on. It could be ADSI or most likely .Net object. [adsi] uses .setinfo the quest object has a .commitchanges() method so the underlying tech is hidden.
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer