Tuesday, March 3, 2020

Updating Powershell

My work laptop got refreshed / re-imaged.

I put a script together for my friends to update the help files and the Functions in PowerShell V5


We have a proxy server so we need to tell PowerShell to use that.
This works as a script, but not well from paste to command line.
and it will pop up some errors, when It can't find updates for some things.
The error output is acceptable to me.

Update-Powershell.PS1
#Requires -Version 5
#Requires -RunAsAdministrator
Start-Transcript Update-Powershell.txt

#Proxy
$wc = New-Object Net.WebClient
$wc.UseDefaultCredentials = $true
$wc.Proxy.Credentials = $wc.Credentials

#enable TLS*
if ([Net.ServicePointManager]::SecurityProtocol -ne ([Net.SecurityProtocolType].GetEnumNames() | ? { $_ -like "Tls*" }))
{ [Net.ServicePointManager]::SecurityProtocol = ([Net.SecurityProtocolType].GetEnumNames() | ? { $_ -like "Tls*" }) }

#Update Help Files
Update-Help -Force -ErrorAction Continue


#Fix the Repositiory defaults 
Register-PSRepository -Default
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted


Install-Module PowershellGet -Force
Install-PackageProvider -Name NuGet -Force

# Update modules

Get-Module -ListAvailable -verbose | Update-Module -verbose

# Import-Module
#Find-Module -Name PSWriteHTML | Install-Module
Install-Module -Name Az -AllowClobber -Scope AllUsers

Stop-Transcript

notepad Update-Powershell.txt

Please comment if you find this useful or could make improvements / additions.