From f22e475f53db3a68c50e41e447dd8619c49a3a74 Mon Sep 17 00:00:00 2001 From: "James Truher [MSFT]" Date: Thu, 28 Apr 2022 17:02:57 -0700 Subject: [PATCH] Change logic in the testing helper module for determining whether `PSHOME` is writable (#17218) --- test/tools/Modules/HelpersCommon/HelpersCommon.psm1 | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 index 894a85ff14..c971e78676 100644 --- a/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 +++ b/test/tools/Modules/HelpersCommon/HelpersCommon.psm1 @@ -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