Powershell - removing subfolder recursively in a mapped drive getting error Illegal characters in path

62 Views Asked by At

I use a mapped drive to copy folder and files into a Sharpoint directory. Here is my code

net use Q: "\\Sharepoint\Dir" /user:domain\user Password

copy-item "C:\Dir" -Destination Q:\

net use Q: /delete

Now before copying new files everyday I need to remove 1 subfolder and all his files (data of the day before). Then I try

remove-item "Q:\Subfolder" -Recurse -Force

but i'm getting this error

Illegal characters in path '{0}'. (Parameter 'Q:\Subfolder\.')

It's working if i write the whole file path like so

remove-item "Q:\Subfolder\file.ext" -Recurse -Force

But I need to remove all of the subfolder...

Some of my other unsuccessful tries

- remove-item "Q:\Subfolder\*" -Recurse -Force





- remove-item "Q:\\Subfolder" -Recurse -Force







- Get-ChildItem Q: -Directory -Force | ForEach-Object {
               
               $regex = "^te"
               
                       if ($_.BaseName -match $regex) {
                           remove-item $_.BaseName 
                       }

Hope someone can help, thanks !

0

There are 0 best solutions below