Home » Find DSC Resource using Find-DscResource

Find DSC Resource using Find-DscResource

Find-DSCResource cmdlets find DSC resources contained in the modules in the registered repositories. By default, the Find-DSCResource command searches all registered repositories to find desired state configuration (DSC) resources.

The Find-DSCResource returns a PSGetDscResourceInfo object for each module found by the command.

Find-DSCResource uses the Name parameter for the name of the DSC resource and locates the modules in the repository. It returns the module PowerShellGet.

Find DSC Resource in PowerShell
Find DSC Resource in PowerShell

In this article, we will discuss how to use the Find-DSCResource cmdlet in PowerShell to find all DSC resources, find a DSC resource by name and find all DSC modules in a module

PowerShell Find-DSCResource

The Find-DSCResource cmdlet of the PowerShellGet module finds the DSC resources contained in the module.

Syntax

Find-DscResource
    [[-Name] <String[]>]
    [-ModuleName <String>]
    [-MinimumVersion <String>]
    [-MaximumVersion <String>]
    [-RequiredVersion <String>]
    [-AllVersions]
    [-AllowPrerelease]
    [-Tag <String[]>]
    [-Filter <String>]
    [-Proxy <Uri>]
    [-ProxyCredential <PSCredential>]
    [-Repository <String[]>]
    [<CommonParameters>]

Let’s understand the Find-DSCResource in PowerShell with the help of examples.

Find all DSC Resources

Use the Find-DSCResource cmdlet in PowerShell to find all DSC resources. It returns DSC resources from registered repositories.

Find-DscResource | Select-Object -First 10  

In the above PowerShell script, the Find-DSCResource returns all DSC resources from the registered repositories and is piped to the Select-Object command.

The Select-Object cmdlet uses the First parameter to display the first 10 results.

The output of the above PowerShell script to get all DSC resources is:

PS C:\> Find-DscResource | Select-Object -First 10                                                                      
Name                                             Version    ModuleName                          Repository
----                                                    -------         ----------                                       ----------
AdvancedBootOptions                 2.6.0      DellBIOSProvider                    PSGallery
AdvancedConfigurations             2.6.0      DellBIOSProvider                    PSGallery
BIOSSetupAdvancedMode          2.6.0      DellBIOSProvider                    PSGallery
BootSequence                               2.6.0      DellBIOSProvider                    PSGallery
IntelSoftwareGuardExtensions   2.6.0      DellBIOSProvider                    PSGallery
Maintenance                                  2.6.0      DellBIOSProvider                    PSGallery
Manageability                                2.6.0      DellBIOSProvider                    PSGallery
MiscellaneousDevices                 2.6.0      DellBIOSProvider                    PSGallery
Performance                                2.6.0      DellBIOSProvider                    PSGallery
POSTBehavior                             2.6.0      DellBIOSProvider                    PSGallery

Find a DSC Resource by Name

Use the Find-DSCResource cmdlet to find DSC resources by name.

Find-DscResource -Name XSqlAlias

In the above PowerShell script, Find-DSCResource locates DSC Resources by the name XSqlAlias. It returns an array of DSC resources.

The output of the above PowerShell script to find DSC resources by name is:

PS C:\> Find-DscResource -Name XSqlAlias                                                                                
Name                                Version    ModuleName             Repository
----                                           -------    ----------                          ----------
xSqlAlias                           1.4.0.0    xSqlPs                            PSGallery
xSqlAlias                           1.0.0.3    mlSqlPs                         PSGallery
xSQLAlias                           8.2.0.6    mlxSQL                        PSGallery


PS C:\>     

Find all DSC resources in a Module

Use the Find-DSCResource to find all the DSC resources contained in the specified module.

Find-DscResource -ModuleName xSqlPs

The Find-DSCResource cmdlet uses the ModuleName parameter to specify the xSqlPs and returns all the DSC resources contained in the module.

The output of the above PowerShell script to find all DSC resources in a module is:

PS C:\> Find-DscResource -ModuleName xSqlPs                                                                             
Name                                Version    ModuleName                          Repository
----                                      -------        ----------                          ----------
xSqlAlias                           1.4.0.0    xSqlPs                              PSGallery
xSqlHAEndPoint              1.4.0.0    xSqlPs                              PSGallery
xSqlHAGroup                   1.4.0.0    xSqlPs                              PSGallery
xSqlHAService                  1.4.0.0    xSqlPs                              PSGallery
xSqlServerInstall              1.4.0.0    xSqlPs                              PSGallery
xWaitForSqlHAGroup     1.4.0.0    xSqlPs                              PSGallery


PS C:\>   

Find DSC Resource using Filter

Use the Find-DSCResource to find all resources using the Filter parameter.

It filters the results by Domain.

Find-DscResource -Filter Domain | Select-Object -First 10  

The output of the above PowerShell script is:

PS C:\> Find-DscResource -Filter Domain | Select-Object -First 10                                                       
Name                                                 Version    ModuleName                          Repository
----                                                          ------    ----------                          ----------
Computer                                          8.5.0      ComputerManagementDsc               PSGallery
OfflineDomainJoin                           8.5.0      ComputerManagementDsc               PSGallery
PendingReboot                                 8.5.0      ComputerManagementDsc               PSGallery
PowerPlan                                         8.5.0      ComputerManagementDsc               PSGallery
PowerShellExecutionPolicy            8.5.0      ComputerManagementDsc               PSGallery
RemoteDesktopAdmin                   8.5.0      ComputerManagementDsc               PSGallery
ScheduledTask                                 8.5.0      ComputerManagementDsc               PSGallery
SmbServerConfiguration               8.5.0      ComputerManagementDsc               PSGallery
SmbShare                                         8.5.0      ComputerManagementDsc               PSGallery
SystemLocale                                   8.5.0      ComputerManagementDsc               PSGallery


PS C:\>

Conclusion

I hope the above article on how to find DSC resources in PowerShell is helpful to you.

If the DSC resource name exists in multiple modules, use the ModuleName parameter to specify the module for installation.

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.