Change logic in the testing helper module for determining whether PSHOME is writable (#17218)

This commit is contained in:
James Truher [MSFT]
2022-04-28 17:02:57 -07:00
committed by GitHub
parent 42ad8b97e2
commit f22e475f53
@@ -326,19 +326,16 @@ function Test-CanWriteToPsHome
return $script:CanWriteToPsHome
}
$script:CanWriteToPsHome = $true
$script:CanWriteToPsHome = $false
try {
$testFileName = Join-Path $PSHOME (New-Guid).Guid
$null = New-Item -ItemType File -Path $testFileName -ErrorAction Stop
$script:CanWriteToPsHome = $true
Remove-Item -Path $testFileName -ErrorAction SilentlyContinue
}
catch [System.UnauthorizedAccessException] {
$script:CanWriteToPsHome = $false
}
finally {
if ($script:CanWriteToPsHome) {
Remove-Item -Path $testFileName -ErrorAction SilentlyContinue
}
catch {
; # do nothing
}
$script:CanWriteToPsHome