Summary: In this blog post, I provide a quick overview of the PowerShellGet module and its various commands.
Believe it or not, the Windows PowerShell Saturday event in Tampa, Florida is coming up pretty quickly. There are still some tickets available, but they have been going pretty quickly lately. There are some awesome speakers coming to Tampa for this event and I am looking forward to seeing all of them. Something really cool is that Ashley McGlone is coming from Columbus, Ohio for the event. I was his mentor for a couple of years, and it is really great to see how successful he has become. In fact, we are getting together after the PowerShell Summit in Seattle to record a couple sessions for a Microsoft Virtual Academy (MVA) course. Several speakers from Tampa will also be involved in this project. I can say that we have a blue ribbon roster of speakers for our event in Tampa—all of whom are well known in the Windows PowerShell community. Ashley asked me to talk a bit about the PowerShellGet module and package management in Windows PowerShell for the MVA course we will be doing. With this in mind, I have been playing with Windows PowerShellGet more.
Explore the PowerShell Get module
The first thing that I do when I am looking at something new, or when I want to refresh my memory about something is to look at the module. Because most stuff in Windows PowerShell ships in a module now, it is always a safe bet that there is a module. I can use
Get-Module to list all modules, and then I can search through the list. But in this case, I happen to know that the module is PowerShellGet, so I don’t need to do that. I type the following command, but the results are a bit muddled because the ExportedCommands is a collection, and it needs to be expanded to make more sense.
PS C:\> Get-Module PowerShellGet | select ExportedCommands
ExportedCommands
----------------
{[Find-DscResource, Find-DscResource], [Find-Module, Find-Module], [Find-Script, ...
The easy way to do this is to use the Expand parameter from Select-Object. Here is the command I use:
Get-Module PowerShellGet | select -EXPAND ExportedCommands
The command and its output are shown here:
From the list of commands, I can see that the first thing I might need to do is to see if I have a registered Windows PowerShell repository. The cmdlet I use is Get-PSRepository:
PS C:\> Get-PSRepository
Name   PackageManagementProvider InstallationPolicy  SourceLocation
---- Â Â ------------------------- ------------------Â Â -----------
PSGallery     NuGet                    Untrusted           https://...
Again, the output is a bit truncated, so I decide to pipe the output to Format-List:
Cool. I can see that I have registered the PSGallery and that it uses NuGet as the package management provider. I also see the publish location and other locations. It is not a trusted location and the installation policy is listed as untrusted. Sweet.
Finding scripts
I saw that there is a Find-Script command. I also see that there is a script publish and source location in the PSGallery, so I can probably use Find-Script to find a script. I happen to know that one reason for this is so I can easily use script resources with OMS automation. Right now, it is not unreasonable to simply use Find-Script with no parameters and look at the output. There are not that many scripts published to PSGallery at this point. Here is the output from the command:
But if I have an idea as to what I am interested in finding, I can use wildcard characters after Find-Script. Here, I look for a script that may have the letters automat in the name:
PS C:\> Find-Script *automat*
Version   Name           Type      Repository          Description
-------Â Â Â ----Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ----Â Â Â Â Â Â ----------Â Â Â Â Â Â Â Â Â Â -----
1.0       Start-AutomationChildRunbook     Script    PSGallery           Th...
1.0       Create-AutomationReport          Script    PSGallery           Th...
Once again, I have the truncated output. I am most interested in the name and description. I use Format-Table and -Wrap to help me get better output:
Find-Script *automat* | Format-Table name, description -Wrap
This command and its output are shown here:
Join me tomorrow when I will talk about finding DSC resources. I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. Also check out my Microsoft Operations Management Suite Blog. See you tomorrow. Until then, peace. Ed Wilson, Microsoft Scripting Guy  Â
0 comments