Author Posts

April 11, 2017 at 11:16 am

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 column B looks like.

Column B (edmpolicy)
APP40_CACHE_WIN7_TMPCLN_100512 APP40_CACHE_CLEAN_100412 BUFFER_FIX_052512

What I would like it to look like.

Column B (edmpolicy)
APP40_CACHE_WIN7_TMPCLN_100512
APP40_CACHE_CLEAN_100412
BUFFER_FIX_052512

April 11, 2017 at 10:55 pm

Unfortunately I don't know what attribute "edmpolicy" is. I could not find an attribute with this name in my environment. Anyway – to make your code a little more readeble you could change it to this:

 get-adgroup -Filter { name -notlike "*_dom1*" -and name -notlike "*MAN*" } -Properties * -SearchBase "ou=esd,dc=dom1,dc=sch,dc=com" | 
        Select-Object -Property name,edmpolicy | 
            ForEach-Object {$_ -replace '\+SOFTWARE\/',"   "} | 
                Export-CSV -FilePath 'c:\sample\ZSTREE.csv' -Delimiter ',' -Encoding UTF8 -NoTypeInformation

If you like to "edit" a particular attribute you could use calculated properties. But because I don't know how the original attribute content looks like I cannot give a suggestion. If your AD attribute is a collection of properties (an array) it will end up in a single "cell" of the csv file anyway.