none
Import CSV to Move User to New OU RRS feed

  • Question

  • Currently, I have a large list that allows the user to select the OU of a newly created user. I am able to successfully get that to work, export the DN of that user to a CSV file, but I need to import it back into a Move-ADObject command.

    Below is current script to get user DN and export:

    $DN = Get-ADUser $SamName -Properties DistinguishedName | Select-Object DistinguishedName | Export-CSV OUout.csv -notypeinformation

    I need to Import the "Distinguished Name" portion back out of the CSV and set it as the Identity for the Move-ADObject -Identity XXX -TargetPath $OU.

    I've tried several different options but I haven't found one that works.

    Thanks!

    Thursday, March 16, 2017 4:22 PM

Answers

  • Sounds like  poorly asked question:

    Get-AdUser | Move-AdObject -TargetPath $OUPath.


    \_(ツ)_/

    • Marked as answer by ydde Thursday, March 16, 2017 7:21 PM
    Thursday, March 16, 2017 6:34 PM
  • Figured it out.

    Get-ADUser $SamName -Properties DistinguishedName | Select-Object DistinguishedName | Export-CSV OUout.csv -notypeinformation
    Import-CSV OUout.csv | ForEach {Move-ADObject -Identity $_.DistinguishedName -TargetPath $OU}

    Thanks!

    • Marked as answer by ydde Thursday, March 16, 2017 7:02 PM
    Thursday, March 16, 2017 7:02 PM

All replies

  • Here is one way:


    Get-ADUser $SamName |
      Select-Object -ExpandProperty DistinguishedName |
    Get-ADPathname -Format X500Parent
    

    Get the Get-ADPathname script here:

    Windows IT Pro: Use PowerShell to Handle Active Directory Paths


    -- Bill Stewart [Bill_Stewart]

    Thursday, March 16, 2017 4:43 PM
    Moderator
  • Sounds like  poorly asked question:

    Get-AdUser | Move-AdObject -TargetPath $OUPath.


    \_(ツ)_/

    • Marked as answer by ydde Thursday, March 16, 2017 7:21 PM
    Thursday, March 16, 2017 6:34 PM
  • Figured it out.

    Get-ADUser $SamName -Properties DistinguishedName | Select-Object DistinguishedName | Export-CSV OUout.csv -notypeinformation
    Import-CSV OUout.csv | ForEach {Move-ADObject -Identity $_.DistinguishedName -TargetPath $OU}

    Thanks!

    • Marked as answer by ydde Thursday, March 16, 2017 7:02 PM
    Thursday, March 16, 2017 7:02 PM
  • It only takes one line.

    Get-AdUser $samname | Move-AdObject -TargetPath $OU

    if you want a record then:

    Get-AdUser $samname | Move-AdObject -TargetPath $OU -PassThru | Select DistinguishedName | Export-Csv <file>

    Or;

    Get-AdUser $samname | Move-AdObject -TargetPath $OU -Verbose


    \_(ツ)_/

    Thursday, March 16, 2017 8:02 PM