Skip to content

Commit f22e475

Browse files
authored
Change logic in the testing helper module for determining whether PSHOME is writable (PowerShell#17218)
1 parent 42ad8b9 commit f22e475

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

test/tools/Modules/HelpersCommon/HelpersCommon.psm1

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,19 +326,16 @@ function Test-CanWriteToPsHome
326326
return $script:CanWriteToPsHome
327327
}
328328

329-
$script:CanWriteToPsHome = $true
329+
$script:CanWriteToPsHome = $false
330330

331331
try {
332332
$testFileName = Join-Path $PSHOME (New-Guid).Guid
333333
$null = New-Item -ItemType File -Path $testFileName -ErrorAction Stop
334+
$script:CanWriteToPsHome = $true
335+
Remove-Item -Path $testFileName -ErrorAction SilentlyContinue
334336
}
335-
catch [System.UnauthorizedAccessException] {
336-
$script:CanWriteToPsHome = $false
337-
}
338-
finally {
339-
if ($script:CanWriteToPsHome) {
340-
Remove-Item -Path $testFileName -ErrorAction SilentlyContinue
341-
}
337+
catch {
338+
; # do nothing
342339
}
343340

344341
$script:CanWriteToPsHome

0 commit comments

Comments
 (0)