locked
PowerShell script to copy user RRS feed

  • Question

  • Does anyone know how to copy a users organizational unit?
    So far i have tried this:

    $SName = Read-Host "Please Enter the login initials of the source user "
    $Path = Get-QADUser -Identity $SName|Select "ParentContainer"
    $FirstName = read-host -Prompt "Enter first name of new user: "
    $LastName = read-host -Prompt "Enter last name of new user: "
    $DName = Read-Host "Please Enter logon initials of the new user "
    $TempPassword = read-host -AsSecureString -Prompt "Enter temporary password (min. 8 characters)"
    $DisplayName = "$Firstname $LastName"
    $PreferredServer = 'dc01.scangl.com'
    start-sleep -s 3
    set-adserversettings -preferredserver $PreferredServer

    Get-QADUser $SName -export|New-QADUser -ParentContainer $Path -Name $DisplayName -SamAccountName $DName -DisplayName $DisplayName -FirstName $FirstName -LastName $LastName -UserPassword $TempPassword

    But the $path is not working.

    It does work, if i set an exact path, but it would be great if copying the OU path is possible.

    Wednesday, September 19, 2012 3:18 PM

Answers

  • Try:

    $Path = Get-QADUser -Identity $SName|Select -expand "ParentContainer"


    Grant Ward, a.k.a. Bigteddy

    • Proposed as answer by Yan Li_ Tuesday, September 25, 2012 6:48 AM
    • Marked as answer by Yan Li_ Tuesday, September 25, 2012 6:48 AM
    Wednesday, September 19, 2012 3:28 PM