Forum Discussion

RobinB93's avatar
RobinB93
Copper Contributor
Aug 14, 2025

Problem with Copy-Item

I'm trying to copy all files from a webdav folder to a local folder. It worked one time, after that, just a file with the the expected folder name (back) was created. What could be the issue?

 

# Define Drive
$netzLaufwerk = "Z:"

# Connect
net use $netzLaufwerk $webdavUrl /user:$username $passwort

# Copy files
Copy-Item -Path "$netzLaufwerk\*" -Destination "C:\Users\innov\Desktop\Backup\back" -Recurse
# Disconnect
net use $netzLaufwerk /delete

1 Reply

  • Vern_Anderson's avatar
    Vern_Anderson
    Copper Contributor

    You're not sharing with us what is inside of the $webdavUrl variable.

    You either. . .
    1. Forgot to set $webdavUrl = "\\servername\sharename"
    2. Or you're not using "net use" correctly

    The NET USE command wants a UNC path so unless the variable $webdavUrl contains a UNC path your script will fail to map the Z: drive. Example: "NET USE Z: \\ServernName\$WEBDAVShare"

    also type "NET USE" by itself to see if Z: is already mapped or never disconnected properly from the last time you ran your script. drive mappings have a tendency to stick until you close the session or delete them as you do in your last line of your code.

    Aside from that I would start to learn how to use the "Join-Path" CMDLET it will give you more reliable actual path objects instead of strings that PowerShell can sometimes trip over, and not treat them as an actual path. 
    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/join-path?view=powershell-7.5

Resources