Skip to content

Instantly share code, notes, and snippets.

@robv8r
Last active August 20, 2017 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robv8r/485fb6a1d68e08fc732fefe4fab2e7f1 to your computer and use it in GitHub Desktop.
Save robv8r/485fb6a1d68e08fc732fefe4fab2e7f1 to your computer and use it in GitHub Desktop.
[CmdletBinding()]
param ()
function Install-DscPullServerPrerequisites {
[CmdletBinding()]
param ()
# If NuGet isn’t installed, install it.
$localProvider = Get-PackageProvider -Name NuGet -ListAvailable -ErrorAction SilentlyContinue
$provider = Find-PackageProvider -Name NuGet
if ($localProvider -eq $null) {
Write-Host "Installing NuGet Provider."
$provider | Install-PackageProvider -Force
} else {
Write-Host "NuGet Provider already installed."
}
$modules = @('PowerShellGet', 'PsDscResources', 'xPSDesiredStateConfiguration')
$modules |% {
$moduleName = $_
$module = Find-Module -Name $moduleName
$installed = Get-InstalledModule -Name $moduleName -ErrorAction SilentlyContinue
if ($installed -eq $null) {
Write-Host "Installing $moduleName"
$module | Install-Module -Force
} elseif ($installed[0].Version -lt $module.Version) {
Write-Host "Updating $moduleName"
$module | Update-Module -Force
}
Write-Host "Importing Module '$moduleName'"
Import-Module -Name $moduleName -RequiredVersion $module.Version
}
}
Install-DscPullServerPrerequisites
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment