Challenge: Changing content of txt-file according to another txt-file with PowerShell
hey,
i got task college of mine , first thing thought monkey it. in other words; let's script it.
we renaming bunch of ad-groups because migrate them domain, , can't have duplicates.
this got work with:
i got 1 txt-file (file1) bunch of ad-groupnames, renamed. example:
g_lolgroup
g_exgroup
g_adgroup
g_hagroup
i got second txt-file (file2) bunch of ad-groupnames, , fun happens. example:
g_lolgroup
g_exgroup
g_adgroup
g_nogroup
g_hagroup
what need this..: foreachmatch between file1 , file2, add ¤groupname+_1 after matching group .
file2 end looking this:
g_lolgroup¤g_lolgroup_1
g_exgroup¤g_exgroup_1
g_adgroup¤g_adgroup_1
g_nogroup
g_hagroup¤g_hagroup_1
appreciate can get, because can't wrap head around this.
get-content file1.txt,file2.txt | group | foreach { $gr = $_.name if($_.count -eq 1) { $gr } else { $gr +"¤" + ((1..$_.count | {$_- 1 -ne 0} | foreach {$gr+"_"+($_ - 1)}) -join ",") } }
Windows Server > Windows PowerShell
Comments
Post a Comment