【发布时间】:2019-08-02 03:05:13
【问题描述】:
我为公共网站上的 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 中确认它们已成功映射和访问。移动似乎从源中删除,但在目标中不存在。
【问题讨论】:
-
您能确认“Get-ChildItem -Path FilePath: -Include *.pdf -Recurse”部分有效吗?如果是这样,您可以发布返回值吗?
-
您有一个错误 [正如 Maurice van Dorst 所提到的],它为我触发了一个巨大的错误文本红墙。这 ... >>>
Get-ChildItem -Path FilePath:请修复它以匹配您实际运行的内容。**
标签: powershell