When ever I run the below AND there are no .csv files I get an error stating the path is null – which it is as there is nothing there to delete…it does NOT stop the script but I get users thinking there is something wrong as powershell loves to show RED characters and that freaks people out!
How do I let the script run but suppress the error?
CODE:
filter removeallcsv([string]$path = '.')
{
Get-ChildItem $path | Where-Object {$_.Extension -eq ".csv"} | Foreach-Object {$_.fullName}
}
Remove-Item (removeallcsv)
You can use an
Ifstatement:One liner: