Summary: Dr. Scripto shows our Admin friend how to determine which groups a computer is a member of.

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: 

Take it away, Sean…

When we last were within our reading, the good Dr. Scripto showed our former non-scripter how to find cmdlets within a module—and furthermore, how to obtain the necessary Help for basic use. The weight of the pressure had begun to ease off our happy admin.  He actually foresaw being home with his family for the holidays.

But now, let the rhyming begin anew!

When last we did see

Our new Admin guy,

He was feeling his scripting

Would be very fly.

 

He learned how to find

Cmdlets with ease.

These PowerShell things

Just working with ease.

 

“So my good friend,”

Said Scripto the Doc,

“What’s the next thing here,

Upon our time clock?”

 

The Admin looked,

And saw on his task list,

A nasty wee thing

He almost had missed.

 

He had to migrate

Some accounts for PC

Memberships of groups

That needed to be.

 

Carried over from an

Old system now,

If he didn’t, the boss

Just might have a cow.

 

But he realized and thought

An answer quite quick,

A solution presented

Itself in a tic!

 

“Why, all of the names

For computers to be

Are sitting right here

In computer.csv.

 

I wonder if can use

The feature from last

Import-CSV,

From the script from the past.”

 

The good doctor nodded

And said, “Give it a try.

You’ve nothing to lose,

And I’ll bet you’ll get by.

 

But even more, I suspect

If you try this and get done,

You’ll be able to access

It, and get yourself done.”

 

The Admin sat down

And examined his stuff,

The data from old

Computers and fluff. 

OLDNAME         NEWNAME

EOT-DABOSS     STATION001

EOT-PICKLE       STATION002

EOT-SURFACE    STATION003

EOT-99             STATION004

EOT-JERRY        STATION005

 $list=IMPORT-CSV computers.csv

 

“Now my next challenge

With this imported list

Is to migrate groups,

Make sure none are missed.”

 

He wondered if a

Cmdlet was there,

To show group memberships,

All without care.

 GET-COMMAND –module ActiveDirectory *group*

 

He look and blinked

At the answers outlaid,

Wondering if they would

Solve and provide aid.

Image of command output

He tried the one out,

It seemed obvious to he,

GET-ADGROUPMember,

It would probably be.

GET-ADGroupmember MicrosoftWord

Image of command output 

He smiled at the result,

It seemed quite a tease,

“But I need to know

The groups for PCs.”

 

“I think I can show you

Just what you need,

You need the property

Of the PC indeed.”

 

Dr. Scripto pulled up

The info at hand,

Of a computer within

The old AD land.

GET-ADComputer EOT-SURFACE –properties memberof

 Image of command output

“See how MemberOf

From the object AD,

Contains the groups

Joined by PC?

 

To get this list out

And useful to you,

We can simply extract it,

So easy to do.”

(GET-ADComputer EOT-SURFACE –properties memberof).memberof

Image of command output

The Admin blinked and saw

Victory in sight,

“Perhaps I’ll be done with

All this tonight!”

Pop in tomorrow for more silly holiday rhymes and a little more Windows PowerShell goodness!

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