Wow. I must be on the stupid pills today. I'm using a simple Test-Path in a script and I cannot figure out why it doesn't enter the IF block when the file is present. I run the same code in the ISE command window and it works fine:
$allfile="c:\users\rs02130\desktop\sonarRules\jsrulesall.xlsx"
Write-Output "Testing $allfile"
if (Test-Path $allfile)
{
Write-Output "In If"
try
{
Write-Output "Removing $allfile"
Remove-Item $allfile -Force -ErrorAction Stop
Write-Output "Removed $allfile"
}
catch
{
Write-Error "Error removing $allfile"
exit 1
}
}
Clearly I'm missing something fundamental but I don't get it. The full original script has similar code in another region and it works fine.
Aucun commentaire:
Enregistrer un commentaire