Last active
January 27, 2023 09:34
-
-
Save sheldonhull/8d6098b87566d2553213d7bb5425490d to your computer and use it in GitHub Desktop.
[Install-Choco] Install chocolatey using powershell dsc #powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
configuration ChocoFeatures { | |
Import-DscResource -ModuleName cChoco | |
Node 'localhost' { | |
cChocoFeature powershellHost { | |
FeatureName = "powershellHost" | |
Ensure = 'Absent' | |
} | |
cChocoFeature allowGlobalConfirmation | |
{ | |
FeatureName = "allowGlobalConfirmation" | |
Ensure = 'Present' | |
} | |
cChocoFeature useRememberedArgumentsForUpgrades | |
{ | |
FeatureName = "useRememberedArgumentsForUpgrades" | |
Ensure = 'Present' | |
} | |
cChocoFeature showDownloadProgress | |
{ | |
FeatureName = "showDownloadProgress" | |
Ensure = 'Absent' | |
} | |
} | |
} | |
$config = ChocoFeatures | |
Start-DscConfiguration -Path $config.psparentpath -Wait -Verbose -Force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Enable-PSRemoting -SkipNetworkProfileCheck -Force | |
Set-ExecutionPolicy Unrestricted -Force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Description | |
Been playing around with using PowerShell DSC to configure some basic resources, and this one is promising. | |
I have stuck mostly with doing this via nuget, but this is also a viable option and i like that it sets the default install path too so you can use a custom path easily | |
#> | |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; | |
set-location (New-Item 'C:\temp' -ItemType Directory -Force) | |
Install-Module PSDscResources | |
Install-Module cChoco | |
$ErrorActionPreference = 'Stop' | |
$ChocoInstallDrive = 'C' | |
$ChocoCacheDIrectory = ('{0}:\temp\choco-cache' -f $ChocoInstallDrive) | |
New-Item -Path $ChocoCacheDirectory -ItemType Directory -Force -ErrorAction SilentlyContinue | |
#https://github.com/dsccommunity/xWindowsUpdate/issues/91 | |
Configuration myChocoConfig | |
{ | |
Import-DscResource -ModuleName PSDscResources | |
Import-DscResource -ModuleName cChoco | |
node "localhost" | |
{ | |
LocalConfigurationManager | |
{ | |
DebugMode = 'ForceModuleImport' | |
} | |
#https://chocolatey.org/docs/chocolatey-configuration#general | |
cChocoInstaller installChoco | |
{ | |
InstallDir = 'C:\choco' | |
} | |
} | |
} | |
try | |
{ | |
Write-Host "⚡ Initiating myChocoConfig" | |
myChocoConfig | |
Start-DscConfiguration myChocoConfig -wait -Verbose -force | |
} | |
catch | |
{ | |
throw | |
exit 1 | |
} | |
try | |
{ | |
$ENV:PATH += ';C:\ProgramData\Chocolatey' | |
choco --version | |
choco config set cacheLocation $('{0}:\temp\choco-cache' -f $ChocoInstallDrive) | |
choco config set upgradeAllExceptions 'vscode' | |
choco config set commandExecutionTimeoutSeconds 1440 | |
} | |
catch | |
{ | |
Write-Error "🔥 Chocolatey failed to install" | |
throw | |
exit 1 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
check status for package (choco search: https://github.com/MrDKOz/HandyScripts/blob/12295ca13bf180612c2fb61c0710aaf8143eacfe/app-installer.ps1)