#
Get PowerShell 5.1 up to date
Always have your PowerShell 5.1 up to date with the latest NuGet
, PackageManagement
, and PowerShellGet
modules and providers.
#
Admin, admin, admin
Be sure to always run commands in an elevated PowerShell session. Use the below command to check if your current session is running as an administrator:
([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
#
Set Execution Policy
Use the below command to set the execution policy to RemoteSigned
if it is not already set. Bypass
will work too if you are feeling risky.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
#
Install NuGet
Use the below command to install the NuGet
provider if it is not already installed.
if ($(Get-PackageProvider).Name -notcontains "NuGet") {
Install-PackageProvider -Name NuGet -Force
}
#
Install PackageManagement
Use the below command to install the PackageManagement
module if it is not already installed.
$InstalledModule = Get-Module -Name PackageManagement -ListAvailable | Where-Object { $_.Version -ge '1.4.8.1' }
if (-not ($InstalledModule)) {
Install-Module -Name PackageManagement -Force -Scope AllUsers -AllowClobber -SkipPublisherCheck
}
#
Install PowerShellGet
Use the below command to install the PowerShellGet
module if it is not already installed.
$InstalledModule = Get-Module -Name PowerShellGet -ListAvailable | Where-Object { $_.Version -ge '2.2.5'}
if (-not ($InstalledModule)) {
Install-Module -Name PowerShellGet -Force -Scope AllUsers -AllowClobber -SkipPublisherCheck
}
#
Close PowerShell
Close the PowerShell window and open a new one to ensure the changes take effect when running subsequent commands.