Edit CSV file

Welcome Forums General PowerShell Q&A Edit CSV file

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
1 year, 8 months ago.

  • Author
    Posts
  • #68466

    Participant
    Points: 0
    Rank: Member

    Hi, I think I need some more sets of eyes on this and maybe I'm thinking of this wrong. I've been trying to get this to look right for the last couple of days. Maybe it can't be done but I thought I would post it for help. I'm running the following script to get the name and edmpolicy of the filtered AD Groups.

     get-adgroup -Filter { name -notlike "*_dom1*" -and name -notlike "*MAN*" } -Properties * -SearchBase "ou=esd,dc=dom1,dc=sch,dc=com" | select-object name,@{N='edmpolicy';E={$_.edmpolicy}} |  Select-Object -Property name,edmpolicy | Export-Csv -Path c:\progra~1\exports\ZSTREE.csv -delimiter "," –notype
    	(Get-Content c:\progra~1\exports\ZSTREE.csv) | % {$_ -replace '\+SOFTWARE\/',"   "} | out-file -FilePath c:\progra~1\exports\ZSTREE.csv -Force -Encoding ascii 

    I then edit it to take out the +software\ out of all the edmpolicy items and replace it with a couple of spaces. The csv file looks fine except if the edmpolicy has multiple items it places everything in the B column going horizontal. Is there any way to get it to place the multiple edmpolicy items going vertical? For example, here's' what it looks like.

    Column A (AD Group Name) Column B (edmpolicy)
    Default – Maint Lvl 1 APP40_CACHE_WIN7_TMPCLN_100512 APP40_CACHE_CLEAN_100412 BUFFER_FIX_052512

    What I would like it to look like.

    Column A (AD Group Name) Column B (edmpolicy)
    Default – Maint Lvl 1 APP40_CACHE_WIN7_TMPCLN_100512
    APP40_CACHE_CLEAN_100412
    BUFFER_FIX_052512

  • #68736

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    What you want, then, isn't a CSV file.

    Each line in a CSV file needs to have exactly the same structure. The way you'd do this would be to emit a new object per line, with each line having both Column A and Column B.

The topic ‘Edit CSV file’ is closed to new replies.