【问题标题】:Move-Item Failure, move doesnt appear in destination directory no error移动项目失败,移动没有出现在目标目录中没有错误
【发布时间】: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


【解决方案1】:

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

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

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

干杯!

~K

【讨论】:

  • 谢谢,只是在异地自动取款机,但会测试并让您知道我的情况。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-20
  • 2021-07-17
  • 2015-05-18
  • 2016-07-08
  • 1970-01-01
  • 2020-03-31
  • 1970-01-01
相关资源
最近更新 更多