Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

A Holiday Special: Rusty the Red-Eyed Scripter, Part 2

$
0
0

Summary: Rusty the Red-Eyed Scripter discovers how Windows PowerShell 5.0 can pull modules from a central repository.

   Note This is Part 2 in a five-part series. To get started, read Rusty the Red-Eyed Scripter, Part 1.

We return with Rusty sitting beside his new friend Thomas from Edmonton, all invigorated to check out Windows PowerShell 5.0.

Rusty was quite interested in this PowerShell Saturday presentation about PowerShell 5 because it seems to offer a stronger level of ease-of-use from the PowerShell 1.0 version he had tried years ago.

The speaker began discussing how PowerShell provides a new method to automatically find modules. Rusty was puzzled. “I can find modules right now. I just go to Bing and search for them, then download the ones I want to my Documents folder,” he mentioned to Thomas.

Thomas smiled. “…and what if there was a cmdlet in PowerShell that could not only find them but automatically download them and place them in a common path?”

Rusty’s mouth dropped to the ground, “Wwwwhhhhhaaaat??”

Thomas smiled a wry grin at his new friend, “Listen to the next bit from the speaker and you’ll see.”

The speaker (who tended to move about like a skittish squirrel) was talking all about the new PowerShell Gallery, a built-in module repository for PowerShell. He began to discuss the new cmdlets in the PowerShellGet module that comes with PowerShell 5.0.

“Our first cmdlet is called Find-Module. It reaches out to see all of the available modules in the PowerShell Gallery. This list of modules is presently populated by Microsoft staff and a select group of community individuals to maintain quality.”

The speaker showed the Find-Module cmdlet in action. “For example, if I would like to find a module called LocalAccount, I can key in this command:”

Find-Module –name Localaccount

Image of command output

“If we’d like to get a better view of the description, of course we can drop this into Format-List:”

Find-Module –name Localaccount | Format-List

Image of command output

“Afterwards, I can install it by specifying the name directly or simply piping the content to the Install-Module cmdlet.”

Find-Module –name Localaccount | Install-Module

Rusty thought that was cool—except for the thought going through his head, “But what if I don’t know the name of the module? This assumes I know the name!”

Almost as if the speaker could somehow read his thoughts (or had some funky Jedi power), he began to speak the answer, “But let’s presume you don’t know the module name. We can filter on the Description property and find all modules that might fit a particular description.”

Find-Module | Where { $_.Description –match ‘local’ }

Image of command output

The speaker continued, “And because this is all PowerShell, I can run it through Out-Gridview to allow to me to cherry-pick the modules I want.”

Find-Module | Where { $_.Description –match ‘local’ } | Out-Gridview –passthru | Install-Module

Image of command output

Poor Rusty. When he saw this in action he almost fell out of his chair. Then the speaker simply clicked a module name and hit ENTER to install it directly on his computer.

“By the way,” our skittish speaker went on, “If you ever need to see if there is an updated version of a module, you can run the Update-Module cmdlet, for example:”

Update-Module –name localaccount

As the presentation continued, the speaker discussed how it would not only work with the PowerShell Gallery, but it could also target many other repositories, including those for a company’s internal sources.

The speaker continued on by pointing out the work the community was doing directly with Microsoft on the GitHub repository.

“Waaaiit!” Rusty looked at Thomas, “Did I hear that right? GitHub is open source! Microsoft and open source solutions?”

“Welcome to the real world, Neo,” Thomas nudged his friend in the side, “Things have changed in some amazing new ways!”

Rusty was itching to get out the door, but with so much more information about Windows PowerShell 5.0 available tonight, he dare not leave.

…and just who was that mysterious fidgety speaker on stage?

Stay tuned as tomorrow Rusty delves more into this wonderful land of Windows PowerShell 5.0.

I invite you to follow the Scripting Guys on Twitter and Facebook. If you have any questions, send email to them at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, always remember that with great PowerShell comes great responsibility.

Sean Kearney, Honorary Scripting Guy, Cloud and Datacenter Management MVP


Viewing all articles
Browse latest Browse all 3333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>