From b72183952e1a488df58e3f7b592188546b62e3a4 Mon Sep 17 00:00:00 2001 From: Chirishman Date: Wed, 21 Dec 2016 17:14:55 -0500 Subject: [PATCH] Switch to full Chocolatey, use ScheduledJob Instead of depending on OneGet's unsupported, years out of date implementation, use that only to get the up-to-date version of Chocolatey. Schedule daily update to run as a PSScheduled Job, enforce that it should run elevated and let the implicit credentials used when executing the script authorize the job where the previous script threw an error if there was no local user with the explicitly configured name of "admin". This method requires PS 5.0 and up but since this script is for Windows 10 that is not a concern. --- utils/install-basic-software.ps1 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/utils/install-basic-software.ps1 b/utils/install-basic-software.ps1 index 9566505..6c47646 100644 --- a/utils/install-basic-software.ps1 +++ b/utils/install-basic-software.ps1 @@ -32,16 +32,25 @@ $packages = @( echo "Setting up Chocolatey software package manager" Get-PackageProvider -Name chocolatey -Force +echo "Setting up Full Chocolatey Install" +Install-Package -Name Chocolatey -Force -ProviderName chocolatey +$chocopath = (Get-Package chocolatey | ?{$_.Name -eq "chocolatey"} | Select @{N="Source";E={((($a=($_.Source -split "\\"))[0..($a.length - 2)]) -join "\"),"Tools\chocolateyInstall" -join "\"}} | Select -ExpandProperty Source) +& $chocopath "upgrade all -y" +choco uninstall mm-choco.extension --all-versions +choco install chocolatey-core.extension --force + echo "Creating daily task to automatically upgrade Chocolatey packages" # adapted from https://blogs.technet.microsoft.com/heyscriptingguy/2013/11/23/using-scheduled-tasks-and-scheduled-jobs-in-powershell/ -$taskName = "Chocolatey Daily Upgrade" -$taskAction = New-ScheduledTaskAction –Execute C:\programdata\chocolatey\choco.exe -Argument "upgrade all -y" -$taskTrigger = New-ScheduledTaskTrigger -At 2am -Daily -$taskUser = "Admin" -Register-ScheduledTask –TaskName $taskName -Action $taskAction –Trigger $taskTrigger -User $taskUser +$ScheduledJob = @{ + Name = "Chocolatey Daily Upgrade" + ScriptBlock = {choco upgrade all -y} + Trigger = New-JobTrigger -Daily -at 2am + ScheduledJobOption = New-ScheduledJobOption -RunElevated -MultipleInstancePolicy StopExisting -RequireNetwork +} +Register-ScheduledJob @ScheduledJob echo "Installing Packages" -Install-Package -Name $packages -Force -ProviderName chocolatey +$packages | %{choco install $_ --force -y} echo "Installing Sysinternals Utilities to C:\Sysinternals" $download_uri = "https://download.sysinternals.com/files/SysinternalsSuite.zip"