Question

I have groups, group1 and group 2, ranging from A to Z... group1-A, group2-A, group1-B, group2-B

I'd like to run through and script is so it takes every member from group1-A, adds them to group2-A, then deletes group1-A [without stopping for confirmation].

I currently have a cmd pipe that will add from one group to another. then i run another to delete the original group, then hit y to confirm. I then up arrow 2 times, and change the letter of the alphabet, and re do..

get-adgroupmember group1-A | foreach { add-adgroupmember -identity group2-A -members $_ 

then

remove-adgroup group1-A

then Y to confirm.

Any way I can throw this so it just iterates through evevery group from A to Z, adds, then deletes?

Was it helpful?

Solution

I can't try it myself but you can do something like :

0..25 | % {[char]($_+65)} | % {$a=$_;get-adgroupmember group1-$a | foreach { add-adgroupmember -identity group2-$a -members $_ }; remove-adgroup group1-$a -force}

The first two pipes are generating letters from 'A' to 'Z' then % is an alias for the Foreach-object Cmdlet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top