none
modifying the "info" AD attribute AKA the large "Notes:" field in the Telephones tab RRS feed

  • Question

  • Hello all! I am totally new to the Powershell arena but I have created this fantastic script that, copies one of our AD templates and creates a new user, with all of that information from a csv. There is only one issue I have: I wish to populate the "Notes:" field in the Telephones tab. I have this information in a column in the csv I mentioned. The field receives the data but the data also contains line breaks or new line characters. That in the information that doesn't carry over so when I open the record to review it, the data is all one line. Any ideas? I'm spent...
    Monday, June 8, 2015 7:03 PM

Answers

  • Use -Replace (instead of -Add) to update the field instead of adding to it. Also, I discovered that you will need to write it this way:


    info=($usersplit -replace ";","`r`n") ...


    -- Bill Stewart [Bill_Stewart]

    Tuesday, June 9, 2015 7:18 PM
    Moderator
  • FYI - this usually works:

    $info=$csv.Info -split ';' | Out-String

    Out-String of an array adds CrLf but saves it in a string and not an array.

    The replace with a variable aloos needs to be done like this:

    -replace @{Info="$info"}

    PowerShell tries to convert it back to an array before passing.


    \_(ツ)_/



    • Edited by jrv Tuesday, June 9, 2015 7:31 PM
    • Marked as answer by Matthew Victor Wiese Wednesday, June 10, 2015 8:45 PM
    Tuesday, June 9, 2015 7:25 PM

All replies

  • Please post a sample CSV file and a sample command that does not work the way you want.


    -- Bill Stewart [Bill_Stewart]

    Monday, June 8, 2015 7:25 PM
    Moderator
  • Here is the line of scripting that applies the data stored in a csv

    Set-ADUser -HomeDirectory $Hdrive -HomeDrive "H:" -OfficePhone $($user.OfficePhone) -Add @{info=$user.info;ipPhone=$user.ipPhone}

    the "info" column is filled out w/o text wrap and it is all one line. But, when I double click the cell, it shows the original formatting like this:

    Employee Name: XXXXXX

    Department: XXXXX

    Title: XXXXXX

    and so on. I know this can be somewhat confusing so if you are willing to provide insight, I can elaborate more to assist. Thanks for the quick reply!

    Monday, June 8, 2015 8:13 PM
  • Not a spreadsheet, but what does the actual text content of the CSV file look like?

    When you say, "import-csv myCsvFileHere.csv" and look at the "info" property, what is the output?


    -- Bill Stewart [Bill_Stewart]

    Monday, June 8, 2015 8:19 PM
    Moderator
  • the actual text content is like this:

    Employee Name: XXXX XXXXXXXX

    Department: Customer Solutions:Tech Supp

    Title:  Technical Support Specialist

    Manager: XXXX XXXXXX

    Start Date: 15<sup>th</sup> June, 2015

    Location: Dublin

    I double click the cell in the csv and c/p this in. I run my script and this is what I get:

    not sure if you can tell but it's all one line of text. The funny thing is, I'll do a whatif on that and the output retains the formatting/new lines. 

    Monday, June 8, 2015 9:13 PM
  • This is probably because your CSV file has some kind of line terminator in it (not sure how you're creating the CSV file) that PowerShell doesn't recognize.

    One way to get around this kind of problem is to use a delimiter character in your source data, for example:


    line1;line2;line3
    

    Then in PowerShell, use:


    info=$user.info.Split(';')
    


    -- Bill Stewart [Bill_Stewart]

    Monday, June 8, 2015 9:30 PM
    Moderator
  • Thanks for the idea! I didn't know that existed so researching it further has opened a lot of door for me. I have not been able to get it to work with my script, however. There is one question I have; should the data be held in one line and then delimited with the semi colon? The thing is, I am c/p the below screen shot from an email:

    do I need to doctor this data before placing it in the csv?

    Tuesday, June 9, 2015 4:59 PM
  • The data in your CSV file needs to look like this:


    Employee Name: name;Department: department;Title: Recruiting Coordinator
    

    ...etc.

    Now do this test at the PowerShell prompt:


    PS C:\> "Employee Name: name;Department: department;Title: Recruiting Coordinator".Split(';')
    

    Observe the output.


    -- Bill Stewart [Bill_Stewart]

    Tuesday, June 9, 2015 5:18 PM
    Moderator
  • The field in AD is delimited by CrLf pairs.  These can be stor4ed in a CSV but the CSV field must be quoted and the CSV will look broken in notepad.  Lines in Excel will not have this as a delimiter in a cell and may not convert correctly to AD.  You will need to replace the delimiter when storing so it displays correctly in ADUC.  The format in ADUC is optional.  You can use any delimiter you want.

    Bill's method above works fine but you can use any convenient method.  I just use CrLf pairs in a CSV.


    \_(ツ)_/

    Tuesday, June 9, 2015 5:32 PM
  • Correct, it should work with correct newline delimiters. But to reduce confusion, I usually recommend a printable delimiter character.

    -- Bill Stewart [Bill_Stewart]

    Tuesday, June 9, 2015 6:18 PM
    Moderator
  • I'm still getting this puke though

    Set-ADUser : Multiple values were specified for an attribute that can have only one value
    At \\tsi.lan\files\TechnicalOperations\CorpIT\CAMO\ImportCSVs\Active Directory\AD_Import.ps1:79 char:1
    + Set-ADUser -HomeDirectory $Hdrive -HomeDrive "H:" -OfficePhone $($user.OfficePho ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (CN=MW test1,OU=...s,DC=tsi,DC=lan:ADUser) [Set-ADUser], ADException
        + FullyQualifiedErrorId : ActiveDirectoryServer:8321,Microsoft.ActiveDirectory.Management.Commands.SetADUser

    here is what I'm doing:

    I tried using "info=$user.info.Split(';')" in the -Add as well but received the same error. Also, I can confirm that in the csv, the data in each cell within the "info" column, are in double quotes, are on one line, and are delimited with a semi colon.

    Your help is greatly appreciated by the way. Even though I have not been successful with this small piece, I am also learning a great deal via trial and error.

    Tuesday, June 9, 2015 6:52 PM
  • Use -Replace (instead of -Add) to update the field instead of adding to it. Also, I discovered that you will need to write it this way:


    info=($usersplit -replace ";","`r`n") ...


    -- Bill Stewart [Bill_Stewart]

    Tuesday, June 9, 2015 7:18 PM
    Moderator
  • FYI - this usually works:

    $info=$csv.Info -split ';' | Out-String

    Out-String of an array adds CrLf but saves it in a string and not an array.

    The replace with a variable aloos needs to be done like this:

    -replace @{Info="$info"}

    PowerShell tries to convert it back to an array before passing.


    \_(ツ)_/



    • Edited by jrv Tuesday, June 9, 2015 7:31 PM
    • Marked as answer by Matthew Victor Wiese Wednesday, June 10, 2015 8:45 PM
    Tuesday, June 9, 2015 7:25 PM