Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This script can be used to forcibly remove the v3/v4 versions that typically ship with Windows and update to latest from PSGallery
#Requires -RunAsAdministrator
$modules = Get-Module -Name Pester -ListAvailable
if ($null -ne $modules) {
$pesterPaths = (get-item $modules.modulebase).parent.Fullname | Sort-Object -Unique
foreach ($pesterPath in $pesterPaths) {
takeown /F $pesterPath /A /R
icacls $pesterPath /reset
# grant permissions to Administrators group, but use SID to do
# it because it is localized on non-us installations of Windows
icacls $pesterPath /grant "*S-1-5-32-544:F" /inheritance:d /T
Remove-Item -Path $pesterPath -Recurse -Force -Confirm:$false
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
Install-Module -Name Pester -Scope AllUsers -Repository PSGallery -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment