I have a CSV file that lists 59 folder paths that I wish to delete. This is the code I am using-
$Folders = Import-Csv -Path "path to csv file"
foreach ($folder in $Folders){
if (Test-Path $folder) {
Write-Host "Folder Exists"
Remove-Item $folder -Recurse -Force
}
else
{
Write-Host "Folder Doesn't Exists"
}
}
The CSV file looks like this:
folders
E:\path1
E:\path2
E:\path3
However the script does not work and it returns "Folder Doesnt Exist", though they do exist. What am I missing?