none
Adding an additional column to output RRS feed

  • Question

  • Hi guys,

    Can anyone help with the following?

    I'm currently trying to output to a CSV which will include a users SamAccountName, CurrentHomeDrivePath, and a third column with a NewHomeDrivePath. So look somoething like this:-

    User1,\\Olddrive\user1,\\newdrive\user1

    User2,\\Olddrive\user2,\\newdrive\user2

    User3,\\Olddrive\user3,\\newdrive\user3

    So I have a list of users (in a CSV) which I'm looping using Get-aduser and am able to get the first two columns fine. The last column is also pretty straightforward as its always going to be \\newdrive\%username%.

    I just can't work out what I need to do to put that 3rd column into the output, if someone has an example to point me in the right direction it would be appreciated.

    Saturday, March 1, 2014 3:41 PM

Answers

  • Are you sure you don't mean:

    Import-Csv <file> | select users SamAccountName,
          CurrentHomeDrivePath,
          @{N='NewHomeDrivePath';E={"\\newdrive\$($_.SamAccountName)"}}


    ¯\_(ツ)_/¯

    • Marked as answer by Theelk Saturday, March 1, 2014 11:30 PM
    Saturday, March 1, 2014 9:22 PM

All replies

  • What third column?

    Your question is ambiguous.  Are you asking how to export the output of Get-AdUser?  Which attributes do you want to export?

    Get-AdUser -filter * -Properties * | select name, homedrive, samaccountname | Export-csv file.csv

    Where do you expect to get the "new home drive"?  If it does not exist then you can't get it.


    ¯\_(ツ)_/¯

    Saturday, March 1, 2014 4:15 PM
  • I suspect you are thinking of something like this:

    Import-Csv <file> | select users SamAccountName, CurrentHomeDrivePath, @{N='NewHomeDrivePath';{'\\newdrive\%username%'}}

    Is that what you are trying to ask?

    Why do you need this in a CSV?


    ¯\_(ツ)_/¯

    Saturday, March 1, 2014 5:49 PM
  • Hi JRV,

    "What 3rd Column" is exactly where I'm stuck, its not something that I can pull from get-aduser (it doesn't exist), so I would like to add it to the output. As I know it will always be the same format for each user I figured it would be relatively simple.

    This does look exactly what I need.

    Import-Csv <file> | select users SamAccountName, CurrentHomeDrivePath, @{N='NewHomeDrivePath';{'\\newdrive\%username%'}}

    however I get the following error:-

    Missing '=' operator after key in hash literal.
    At line:1 char:112
    + get-aduser User1 | select samaccountname, userprincipalname,  @{N='NewHomeDri
    vePath';{'\\newdrive\%username%'}} <<<<
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
       ception
        + FullyQualifiedErrorId : MissingEqualsInHashLiteral

    Basically this output if I get it working will be the input for a Robocopy script that I have that reads from a CSV file that uses the following columns jobname/username, sourcefolder/currenthomedrive,destinationfolder/Newhomedrive

    Thanks for looking at this.

    Saturday, March 1, 2014 8:54 PM
  • Sorry -  pasting things in this forum is always interesting

    Import-Csv <file> | select users SamAccountName,
          CurrentHomeDrivePath,
          @{N='NewHomeDrivePath';E={'\\newdrive\%username%'}}


    ¯\_(ツ)_/¯

    Saturday, March 1, 2014 9:20 PM
  • Are you sure you don't mean:

    Import-Csv <file> | select users SamAccountName,
          CurrentHomeDrivePath,
          @{N='NewHomeDrivePath';E={"\\newdrive\$($_.SamAccountName)"}}


    ¯\_(ツ)_/¯

    • Marked as answer by Theelk Saturday, March 1, 2014 11:30 PM
    Saturday, March 1, 2014 9:22 PM
  • Perfect! Thanks for your time.
    Saturday, March 1, 2014 11:30 PM