Get-DistributionGroup -Identity * -ResultSize Unlimited | Select-Object name | set-content C:\temp\allDistNames.txt
$names = gc C:\temp\allDistNames.txt
#remove no needed brackets and other signs
$cont = foreach ($n in $names) {
$n.remove(0,7) -replace ".$"
}
$cont | set-content C:\temp\allDistNames.txt
$names = gc C:\temp\allDistNames.txt
foreach ($n in $names) {
Get-DistributionGroupMember -Identity $n -ResultSize Unlimited | Select-Object PrimarySmtpAddress | set-content C:\temp\temp.txt
$mails = gc C:\temp\temp.txt
#remove no needed brackets and other signs
$cont = foreach ($m in $mails) {
$m.remove(0,21) -replace ".$"
}
foreach ($c in $cont) {
#get only not empty mails\lines
if ($c.Length -gt 3) {
#search last 14 characters and compary them
if ($c.substring($c.Length-15) -eq "applypoland.com") {
#put the names of distribution list in text file
$n | out-file c:\temp\listalista.txt -append
}
}
}
}
Below script is using for replace emails ended with applypoland.com to ended with applysorco.no
Get-DistributionGroupMember -Identity testbb | Select-Object PrimarySmtpAddress | set-content C:\temp\testbb1.txt
$mails = gc C:\temp\testbb1.txt
$cont = foreach ($m in $mails) {
$m.remove(0,21) -replace ".$"
}
foreach ($c in $cont) {
if ($c.substring($c.Length-15) -eq "applypoland.com") {
$c | out-file c:\temp\ap.txt -append
$c = $c -replace 'applypoland.com','applysorco.no' | out-file c:\temp\sorco.txt -append
}
}
$usun = gc c:\temp\sorco.txt
foreach ($u in $usun) {
add-DistributionGroupMember -Identity testbb -member $u
}
$dodaj = gc c:\temp\ap.txt
foreach ($d in $dodaj) {
remove-DistributionGroupMember -Identity testbb -member $d -Confirm:$False
}
Brak komentarzy:
Prześlij komentarz