Reputation: 4076
I can recreate the issue with the below code sample
New-PSDrive -Name Z -PSProvider FileSystem -Root \\10.10.22.6\d$ -Credential $cred -Confirm:$false -Scope Global
Set-Content -Path 'Z:\__unc_test\Powershell\___datefile' -Value ([System.DateTime]::Now).ToString()
Get-ChildItem Z:\__unc_test
Get-ChildItem will return a listing of the directory so I know the New-PSDrive call is succeeding and the UNC is available via the Powershell.
However, the Set-Content call is failing with the following error:
Set-Content : Could not find a part of the path '\\10.10.22.6\d$\10.10.22.6\d$\10.10.22.6\d$\__unc_test\Powershell\___datefile'.
At line:1 char:1
+ Set-Content -Path 'Z:\__unc_test\Powershell\___datefile' -Value ([System.DateTim ...
If you look at the error it appears Set-Content is attempting to resolve the path in some manner and is doing something very wacky.
Can anyone try and recreate this on their machine and/or explain to me what I'm doing wrong here? Get-Item, Get-ChildItem, and Copy-Item all seem to work across that drive letter, but not Set-Content.
Upvotes: 5
Views: 3412
Reputation: 1781
I can repro this issue on my machine. This only seems to happen if the file does not exist before you call Set-Content. Easy solution, run this before you use set-content:
New-Item -Path 'Z:\__unc_test\Powershell\___datefile' -Type file -Force
This problem also does not occur if I use "net use" to add the drive.
Upvotes: 6