My Powershell Script checks if a file exits. When it exist, the existing file is deleted. Then a new file with same name is saved. It works perfect when no dots (".") are in my filename (and path). I thought -LiteralPath would be the solution, but it doesn't work, don't know why. Test-Path seems to work, but Remove-Item doesn't work.
$xlsFile = "R:\Temp\37 Place i.Bay.\ComeOn 37 Place i.Bay. user_finance.xlsx"
if (Test-Path -LiteralPath $xlsFile)
{
try {
Write-Host "TestPath positiv, try to delete"
Remove-Item -LiteralPath $xlsFile -ErrorAction "Stop"
} catch {
Write-Warning $_.Exception.Message
}
try {
$xlsObj.ActiveWorkbook.SaveAs($xlsFile);
} catch {
Write-Warning $_.Exception.Message
}
}
else
{
Write-Host "TestPath negativ"
$xlsObj.ActiveWorkbook.SaveAs($xlsFile);
};
Powershell 2.0, R: is a network path.
Thx