I want to transfer more and more logic away from Group Policies towards Windows PowerShell Desired State Configuration (DSC). There are several reasons why i think that DSC is much better than my old (and complex) group policy constructs, but the main reason (at least for me): I can manage DSC clients that are domain joined, not domain joined, or even Azure Active Directory domain joined the same way.

This is also something I use for Edge servers (like Skype or Exchange); they are not domain joined. And if you have more than one that should do exactly the same, this is where DSC could become a life saver and make your life very easy.

I play around with several DSC Push and Pull server instances, but I wanted to have the same set of DSC resources available on all of them. At least until I know which to keep to reduce my own logic.

I use the DSC Script Resource a lot. I do a lot of checks and implemented a lot of logic and flexibility within a lot of Script Resources.
However, this is the wrong way to use DSC! At least, in my opinion!

There are some very cool ready to use DSC resources available, and this reduces the script resource usage (or what I did: abuse). Why should I keep my own logic when someone else created nearly the same as a central and maintained DSC resource?
I know: I’m lazy!

So I created myself the following initial script:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#requires -Modules PowerShellGet
#requires -Version 2.0
#Requires -RunAsAdministrator

<#
		.SYNOPSIS
		Install some DSC Resources
	
		.DESCRIPTION
		Getting, install, or update DSC Resources I want to have. 
		It could be used to install every Module from the Gallery. 
		However, this is something I do with DSC afterwards!
	
		.EXAMPLE
		PS C:\> .\invoke-GetDSCResources.ps1

		.EXAMPLE
		PS C:\> .\invoke-GetDSCResources.ps1 -verbose
		VERBOSE: Populating RepositorySourceLocation property for module PSDscResources.
		VERBOSE: Try to update PSDscResources
		VERBOSE: Updated PSDscResources
	
		.NOTES
		Small script I created for myself.
		I have to prepare DSC systems from time to time, and I want to have the same set of DSC resources on all of them.
		Mainly because I'm lazy, but I'm an old-school Unix guy: Never type something more than two times: AUTOMATE.

		I install the resources system wide!
		That is why we have the Elevated Shell requirement (#Requires -RunAsAdministrator).
		If you want to use it just for the current user, change the Scope in $paramInstallModule from 'AllUsers' to 'CurrentUser'.

		TODO: Pester Test is missing
		DONE: Make it more robust

		Disclaimer: The code is provided 'as is,' with all possible faults, defects or errors, and without warranty of any kind.

		Author: Joerg Hochwald

		License: http://unlicense.org

		.LINK
		Author http://jhochwald.com

		.Link
		License http://unlicense.org
#>
[CmdletBinding()]
param ()

BEGIN
{
	# Define some defaults
	$STP = 'Stop'
	$SC = 'SilentlyContinue'

	# Suppressing the PowerShell Progress Bar
	$script:ProgressPreference = $SC

	# Create a list of the DSC Resources I want
	$NewDSCModules = @(
		'PSDscResources', 
		'xNetworking', 
		'xPSDesiredStateConfiguration', 
		'xWebAdministration', 
		'xCertificate', 
		'xComputerManagement', 
		'xActiveDirectory', 
		'SystemLocaleDsc', 
		'xRemoteDesktopAdmin', 
		'xPendingReboot', 
		'xSmbShare', 
		'xWindowsUpdate', 
		'xDscDiagnostics', 
		'xCredSSP', 
		'xDnsServer', 
		'xWinEventLog', 
		'xDhcpServer', 
		'xHyper-V', 
		'xStorage', 
		'xWebDeploy'
		'xRemoteDesktopSessionHost', 
		'xDismFeature', 
		'xSystemSecurity', 
		'WebAdministrationDsc', 
		'OfficeOnlineServerDsc', 
		'AuditPolicyDsc', 
		'xDFS', 
		'SecurityPolicyDsc', 
		'xReleaseManagement', 
		'xExchange', 
		'xDefender', 
		'xWindowsEventForwarding', 
		'cHyper-V'
	)
}

PROCESS
{
	foreach ($NewDSCModule in $NewDSCModules)
	{
		# Cleanup
		$ModuleIsAvailable = $null

		# Check: Do I have the resource?
		$paramGetModule = @{
			ListAvailable = $true
			Name          = $NewDSCModule
			ErrorAction   = $SC
			WarningAction = $SC
		}
		$ModuleIsAvailable = (Get-Module @paramGetModule)
		
		if (-not ($ModuleIsAvailable))
		{
			# Nope: Install the resource
			try
			{
				Write-Verbose -Message "Try to install $NewDSCModule"

				$paramInstallModule = @{
					Name          = $NewDSCModule
					Scope         = AllUsers
					Force         = $true
					ErrorAction   = $STP
					WarningAction = $SC
				}
				$null = (Install-Module @paramInstallModule)

				Write-Verbose -Message "Installed $NewDSCModule"
			}
			catch
			{
				# Whoopsie
				$paramWriteWarning = @{
					Message     = "Sorry, unable to install $NewDSCModule"
					ErrorAction = $SC
				}
				Write-Warning @paramWriteWarning
			}
		}
		else
		{
			try
			{
				Write-Verbose -Message "Try to update $NewDSCModule"

				# TODO: Implement the check from invoke-ModuleUpdates.ps1 to prevent the unneeded update tries.
				$paramUpdateModule = @{
					Name          = $NewDSCModule
					Confirm       = $false
					ErrorAction   = $STP
					WarningAction = $SC
				}
				$null = (Update-Module @paramUpdateModule)

				Write-Verbose -Message "Updated $NewDSCModule"
			}
			catch
			{
				# Whoopsie
				$paramWriteWarning = @{
					Message     = "Sorry, unable to update $NewDSCModule"
					ErrorAction = $SC
				}
				Write-Warning @paramWriteWarning
			}
		}
	}
}

END {
	# No longer suppressing the PowerShell Progress Bar
	$script:ProgressPreference = 'Continue'
}

You could use the same logic to install nearly all modules from the Gallery (or any another valid PowerShellGet Source).
This is something I do via DSC later and based upon the group that the DSC client belongs to; this could be a long list, or even a very short one.

Disclaimer:
The code is provided ‘as is,’ with all possible faults, defects or errors, and without warranty of any kind.