Summary: Learn how to use Windows PowerShell commands to easily find Desired State Configuration resources that are available in the PowerShell Gallery.
One of the cool things about Windows PowerShell is that it makes exploring data easy. And everything is data in some form. Whether it is local or remote, whether it is plain text; a .csv, .tsv, or .xml file…whatever it is, it is still data.
Even a list of cmdlets, functions, scripts, modules, or whatever in the Windows PowerShell world is data—and from a usability stand point, it is valuable data. So I can use Windows PowerShell to learn about what I can do with Windows PowerShell. The PowerShell Gallery makes that an even richer proposition. The PowerShell Gallery home page is shown here:
When I use the Find-DSCResource command, a long list of DSC resources come back:
In fact, when I run it, I get back 461 DSC resources:
PS C:\> Find-DscResource | measure
Count : 461
That is quite a lot of information to scroll through. So, to get an idea of how many DSC resources are in which modules, I decide to group and sort. Here is my command:
Find-DscResource | group modulename | sort count -Descending
Here is the output from the command:
There are quite a few DSC resources in the xSharePoint and xExchange modules, it would appear. To get an idea of how many modules there, I select unique module names:
Find-DscResource | select modulename -Unique
To find how many modules I have, I add measure:
PS C:\> Find-DscResource | select modulename -Unique | measure
Count : 119
Wow, that is quite a lot!
Filter DSC resources
If I want to find a specific DSC resource, I can do one or two things. The first, and perhaps most obvious, is to search by module. For example, if I am interested in doing web things, I may want to find DSC resources that have the letters web in the module name:
Find-DscResource -moduleName *web*
It would appear that I cannot use a wildcard character for the resource name. So, when I type the following queries, I do not get anything back:
PS C:\> Find-DscResource -Name "*update*"
PS C:\> Find-DscResource -Name "*reboot*"
PS C:\> Find-DscResource -Name *reboot*
PS C:\> Find-DscResource -Name *update*
But it also seems that I can use wildcard characters for the module name, for example:
Find-DscResource -moduleName *update*
But the easier way to do things is to use the -Filter parameter. By using this, I can find things I would not otherwise imagine. Here are a few example commands:
Find-DscResource -Filter "update"
Find-DscResource -Filter "reboot"
The cool thing is that the -Filter parameter will search the ModuleName field and the Resource name fields. Here is the output from the two commands:
The good news is that there are now hundreds of DSC resources in the PowerShell Gallery. The even better news is that I can use Windows PowerShell to find them.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at firstname.lastname@example.org, 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