powershell - test-path returns permission denied - how to do error handling -
i try error handling within powershell script. fatal. tried few things, e. g. try{ } catch{ } - did not work.
any ideas or solutions?
function check-path($db) { if ((test-path $db) –eq $false) { write-output "the file $db not exist" break } }
it returns:
test-path : zugriff verweigert in k:\access\access.ps1:15 zeichen:6 + if ((test-path $db) -eq $false) { + ~~~~~~~~~~~~~ + categoryinfo : permissiondenied: (k:\ss.mdb:string) [test-path], unauthorizedaccessexception + fullyqualifiederrorid : itemexistsunauthorizedaccesserror,microsoft.powershell.commands.testpathcommand
somewhat confusingly test-path
generates error in number of cases. set standard erroraction parameter silentlycontinue ignore it.
if ((test-path $db -erroraction silentlycontinue) -eq $false) {
Comments
Post a Comment