Install all DSC Resources in a Repository

Something quick for Friday morning! Are you feeling enthusiastic about DSC? Do you want to update or install every DSC resource in a repository onto your computer?

Try this (only on PowerShell 5.0 computers – what do you mean you’re not using PowerShell 5.0?):

Find-DscResource | Select-Object -ExpandProperty ModuleName -Unique | % { Install-Module -Name $_ -Force }

This will download and install (or update if you’ve got older versions) of all DSC Resources in all PowerShell Repositories registered on your computer. This can definitely take some time.

If you would like to limit this to only using a specific repository use:

$RepoName = 'PSGallery'
Find-DscResource -Repository $RepoName | Select-Object -ExpandProperty ModuleName -Unique | % { Install-Module -Name $_ -Repository $RepoName -Force }

Important Note: I’d suggest you only install DSC resources from repositories you trust. You might therefore want to make sure you’ve marked those repositories as trusted otherwise you’ll need to confirm the installation of each module (which is a little irritating).

To trust a repository:

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s