mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Change logic in the testing helper module for determining whether PSHOME is writable (#17218)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user