首页 > 解决方案 > 移动项目失败,移动没有出现在目标目录中没有错误

问题描述

我为公共网站上的 WebDav 共享编写了以下脚本。目的是列出内部网络共享中的所有 PDF,并将文件移动到网站上的 WebDAV 共享。我可以确认两个 New-PSDrive 映射都成功。然后我移动文件,文件从源中删除,但没有出现在目标中。

当没有出现错误时,我试图找出错误。由于 WebDAV 共享并且以前没有使用过这个,我在这里的逻辑中有什么遗漏吗?

在移动项目中,我也尝试添加 $Path1 然后 -Destination 和 $Path 但失败了。我修改了本地会话路径的脚本,如 C:\Temp 并且工作正常。怀疑 WebDAV 共享有什么不同。

$user = "webdav"
$pass = convertto-securestring -String 'WebDAV Password' -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential($user,$pass)
$user1 = "Domain Account"
$pass1 = convertto-securestring -String 'DOMAIN PASSWORD HERE' -AsPlainText -Force
$cred1 = New-Object -typename System.Management.Automation.PSCredential($user1,$pass1)
[String]$path = '\\constoso.com@SSL/Dav/PDF'
[String]$path1 = '\\Domain\corpdata\PDF'
New-PSDrive -Name WebSite -PSProvider FileSystem -Root $path -Credential $cred
New-PSDrive -Name FilePath -PSProvider FileSystem -Root $path1 -Credential $cred1
Get-ChildItem -Path FilePath: -Include *.pdf -Recurse | Move-Item -Destination $path

使用 WebDAV 共享时,没有错误报告的文件不在目标中,可以在 Get-PSDrive 中确认它们已成功映射和访问。移动似乎从源中删除,但在目标中不存在。

标签: powershell

解决方案


当您使用 PSDrive cmdlet 时,您必须指定“提供者”信息。在您的情况下,UNC 路径属于“文件系统”提供程序。因此,请尝试更改您的“路径”变量,如下所示,

[String]$path = 'Filesystem::\\constoso.com@SSL\Dav\PDF'

[String]$path1 = 'Filesystem::\\Domain\corpdata\PDF'

干杯!

〜K


推荐阅读