‘Twas the Night Before Scripting: Part 5

‘Twas the Night Before Scripting: Part 5

  • Comments 8
  • Likes

Summary: Tonight, our Admin friend learns to migrate group memberships.

Microsoft Scripting Guy, Ed Wilson, here. If you missed it, be sure to watch Sean’s video: Just Script It! Also to catch up with our story, read: 

And now, our conclusion…

During the past four days, we encountered a friend who (with the aid of Dr. Scripto) has learned some basic scripting to accomplish his holiday tasks far more readily. Now he is about to complete his work by deploying and migrating domains.

And now we begin

To work to the end,

To aid in the help

Of our good Admin friend.

 

The users were ready,

With their attributes set,

And the PCs in AD

Were ready to get.

 

But one more task

‘Twas there in the way,

A simple wee thing

To finish the day.

 

“We must now migrate

Your memberships here,

To the new computers

And get you all clear.

 

You were close, I can see,

With the cmdlet you chose,

But ‘twas the reverse,

So I shall show you the close.”

 

Dr. Scripto sat down

On his plastery knee,

To show to Admin

The final piece to set free.

 

“With the info we have

And Import-CSV,

We can combine them as one,

To get done in AD.”

 

To transfer the settings

From and old to a new,

He ran a cmdlet

To get them all through.

 

A cmdlet he typed

On the blue world,

To untangle adding to

The group membership world:

Add-ADGroupMember

 

The Admin added Get-Help,

To see examples on how

To use this new cmdlet,

On his screen there and now:

GET-HELP ADD-ADGroupMember –examples

Image of command output

 

It seemed just too easy,

He tried right away

To add one adhoc,

Went straight off to play!

ADD-ADGroupMember –identity “RDPEnabled” –members “STATION003”

 

But he blinked in dismay,

At what he now saw,

It just didn’t work,

He fell back in awe.

 

Dr. Scripto, he smiled,

“A moment, my friend,

The answer was close,

Almost the end!

 

The trick, the cmdlet,

In the examples you see,

Is use the SAM property,

Of the computer PC.” 

ADD-ADGroupMember –identity “RDPEnabled” –members “STATION003$”

 

“Now all we need do

Is combine the two things,

Your list of computers,

And the membership things!” 

$Computerlist=IMPORT-CSV computers.csv 

Foreach ($PC in $Computerlist)

{

$Groups=(GET-ADComputer $PC.Oldname –properties memberof).memberof

$SamName=$PC.Newname+”$”

$Groups | ADD-ADGroupMember –member $Samname

}

 

The Admin, he saved

And ran that in a lick,

In moments the groups

Were transferred so quick.

 

He looked at the clock,

And realized the time

Had barely been moved,

Not such a crime!

 

500 users were done,

And PCs were set,

No effort required,

And still much time yet.

 

To visit his family,

And resting the ways

Of all well-earned time,

And good holidays.

 

“Dr. Scripto,” he reached

Out to thank him away,

But the mythical, magical man

Had vanished away.

 

A note on his screen

Is all that was found,

“Just Bing me on TechNet,

I’m always around.

 

I live in the spirit

Of the blogs of the net,

Just use #powershell,

Never you fret.

 

MVPs and the like,

Community as well,

Are all that I am,

Just ring on their bell.”

 

A final line was left

For him to read:

www.scriptingguys.com,

Should you feel need.

 

The Admin, he smiled,

Logged his system on down,

Headed outside,

With nary a frown

 

For now, armed with a

Scripting skill set,

He’d always have time,

And never would fret.

 

Happy Holidays from the Scripting Guys!

I invite you to follow the Scripting Guys on Twitter and Facebook. If you have any questions, send email to scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Sean Kearney, Honorary Scripting Guy and Windows PowerShell MVP 

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Gorgeous! Merry Christmas!

  • Nicely wrapped up!!!