Powershell Array with CSV RRS feed

  • Question

  • My HR department gives us an excel document that reflects changes to users that need to be replicated to AD.

    I save the document as a CSV for easier processing with Powershell, however we store our common names as last, first which creates "Quotes" around the comma.

    So in detail, what I'm doing is using this

    $ArrayList = @()
    "ReadLineFromCSV Activity".Split("`n") | ForEach {
    $ArrayList += "$_"

    the lines look like this

    "Doe, John",Senior Manager,ED1222,Project Manager,Wisconsin,"King, Jerry"

    and orchestrator gives me this error...

    At line:3 char:3
    + ""Doe, John",Senior Manager,ED1222,Project Manager ...
    +   ~~~~
    Unexpected token 'Doe' in expression or statement.
    At line:3 char:7
    + ""Doe, John",Senior Manager,ED1222,Project Manager ...
    +       ~
    Missing argument in parameter list.

    Its like it doesn't like the quotes around the comma. any suggestions?

    Thursday, March 3, 2016 5:01 PM


All replies

  • Why not use Import-Csv?

    -- Bill Stewart [Bill_Stewart]

    Thursday, March 3, 2016 5:05 PM
  • Just import it directly. The quotes are there for a reason.

    PS C:\Scripts\PowerShell Scripts\Misc Testing\3-03-2016> cat .\inputFile.csv
    "Doe, John",Senior Manager,ED1222,Project Manager,Wisconsin,"King, Jerry"
    "Someone, Else",More Senior Manager,8675309,Bossman,Alaska,"Larson, Gary"
    PS C:\Scripts\PowerShell Scripts\Misc Testing\3-03-2016> Import-Csv .\inputFile.csv | Format-Table -AutoSize
    H1            H2                  H3      H4              H5        H6          
    --            --                  --      --              --        --          
    Doe, John     Senior Manager      ED1222  Project Manager Wisconsin King, Jerry 
    Someone, Else More Senior Manager 8675309 Bossman         Alaska    Larson, Gary

    EDIT: Ah, slow on Submit. See Bill's post.

    Thursday, March 3, 2016 5:07 PM
  • I tried that, I'm using it in orchestrator to update multiple AD accounts from the array. I just cant seem to tweak it right to update multiple accounts.

    Thursday, March 3, 2016 6:40 PM
  • When you say that something didn't work, you have to say how it didn't work.

    Test from a PowerShell prompt with sample data first to make sure you're doing what you think you're doing.

    -- Bill Stewart [Bill_Stewart]

    Thursday, March 3, 2016 7:17 PM