Home Forums Programming Powershell Remove-Item giving error and not accepting path passed thru variable RE: Remove-Item giving error and not accepting path passed thru variable

  • shahnr21 - Sunday, December 17, 2017 9:44 PM

    Here is the code I am trying:
    ...
    foreach($RowDelete in $resultsDatatable) 
    {  
    echo "Inside For Loop"  
    echo $RowDelete  
    write-host “Deleting Duplicate PDF File/ Letterâ€; 
    # $RowDelete | foreach { $_.Delete()} 
    # $RowDelete | Remove-Item -Recurse -WhatIf -ErrorAction SilentlyContinue  
    Remove-Item -recurse -force $RowDelete -erroraction silentlycontinue -Whatif 
    }
    ...

    And what I am trying to achieve is deleting the above file using Remove-Item in PowerShell script.
    Hope this information helps.

    I realize this was posted a while back, but the -Whatif switch tells Powershell to just test and not actually make any permanent changes.