PowerShell Get-ChildItem how to catch Exception
Add -ErrorAction Stop
to the Get-ChildItem
cmdlet:
if ($checkBox1.Checked) { Try{ Get-ChildItem -path "K:\adm_spm_logdb_data\ADP\DATA" -ErrorAction Stop |Rename-Item -newname { $($_.BaseName -split '_provide')[0] + $_.Extension }; }catch [System.Exception]{ $listBox1.Items.Add("An error occured while trying to process ADP-Files please check the manual!") } $listBox1.Items.Add("Please check your System files to ensure the process has finished") }