Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Need some help with parsing this txt file into a CSV format

$
0
0

Hello Everyone,

What I am trying to do is take this .txt file and convert it to a .csv with the AD group in column one and the users for each group listed next to it in column two equally matched in the two columns. I am trying to run a group removal script against it using the csv file generated. The text file looks similar to this

File looks like this:

some-ad-group1=user01,user02,user03,user04,user05,user06,user07,user08;

some-ad-group2=user01,user02,user03,user04,user05,user06,user07,user08;

some-ad-group3=user01,user02,user03,user04,user05,user06,user07,user08;

some-ad-group4=user01,user02,user03,user04,user05,user06,user07,user08;

some-ad-group5=user01,user02,user03,user04,user05,user06,user07,user08;

some-ad-group6=user01,user02,user03,user04,user05,user06,user07,user08;

 

Trying to get the information to look like this in the CSV File:

some-ad-group1,user01

some-ad-group1,user02

some-ad-group1,user03

some-ad-group1,user04

some-ad-group1,user05

some-ad-group1,user06

some-ad-group1,user07

some-ad-group1,user08

some-ad-group2,user01

some-ad-group2,user02

some-ad-group2,user03

some-ad-group2,user04

some-ad-group2,user05

 

Here is the code I have been messing with. Currently I am just echoing the data into the csv file which is messy and still requires a lot of work.

 

 

$content=Get-ContentC:\Powershell\Files\TestFiles\testremoval2.txt | ForEach-Object {$_-replace";" ,""}foreach ($linein$content) {$split=$line.Split("=")Echo"==============" | Out-Filec:\Powershell\Files\TestFiles\output.csv-AppendEcho$split[0]    | out-filec:\Powershell\Files\TestFiles\output.csv-AppendEcho"==============" | out-filec:\Powershell\Files\TestFiles\output.csv-AppendEcho$split[1].Split(",") | out-filec:\Powershell\Files\TestFiles\output.csv-Append
}


Any help would be greatly appreciated. 

Viewing all articles
Browse latest Browse all 6937

Trending Articles