Forum Discussion
Problem with Copy-Item
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