首页 文章

无法压缩 - 从UNC路径归档

提问于
浏览
0

我正在尝试制作一个脚本,它将自动在网络驱动器上找到正确的文件夹 . 这些是我们用户的主页文件夹 .

我想压缩指定的文件夹并将其放在其他地方 .

当压缩过程开始时,我不断收到网络驱动器上的访问被拒绝的错误 .

我尝试运行提升的powershell,但同样的错误发生 . 这是我制作的剧本:

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null 
$username = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Name ")

$source=Get-ChildItem -Path \\server\Home1, \\server\Home2, \\server\Home3 -Include $username | Select-Object -ExpandProperty FullName

$destination = "C:\testzippowershell\"+$username+".zip"

Compress-Archive -literalpath $source -DestinationPath $destination

这些是由此产生的错误:

Get-ChildItem:指定的网络名称不再可用 . 在C:\ windows \ system32 \ windowspowershell \ v1.0 \ Modules \ Microsoft.PowerShell.Archive \ Microsoft.PowerShell.Archive.psm1:663 char:20 $ dirContents = Get-ChildItem -LiteralPath $ sourceDirPath -Recurse ~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (\ server \ Home3 \ user \ Desktop:String)[Get-ChildItem],IOException FullyQualifiedErrorId:DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand Get-ChildItem:指定的网络名称不再可用 . 在C:\ windows \ system32 \ windowspowershell \ v1.0 \ Modules \ Microsoft.PowerShell.Archive \ Microsoft.PowerShell.Archive.psm1:663 char:20 $ dirContents = Get-ChildItem -LiteralPath $ sourceDirPath -Recurse ~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (\ server \ Home3 \ user \ Documents:String)[Get-ChildItem],IOException FullyQualifiedErrorId:DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand Remove-Item:找不到路径'C:\ testzippowershell \ user.zip',因为它确实不存在 . 在C:\ windows \ system32 \ windowspowershell \ v1.0 \ Modules \ Microsoft.PowerShell.Archive \ Microsoft.PowerShell.Archive.psm1:233 char:21 ... Remove-Item -LiteralPath $ DestinationPath -Force -Recurse .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ CategoryInfo:ObjectNotFound:(C:\ testzippowershell \ user.zip:String)[Remove-Item],ItemNotFoundException FullyQualifiedErrorId:PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand以“0”调用“GetFiles”的异常“参数:”指定的网络名称不再可用 . “在C:\ windows \ system32 \ windowspowershell \ v1.0 \ Modules \ Microsoft.PowerShell.Archive \ Microsoft.PowerShell.Archive.psm1:677 char: 13 $ files = $ currentContent.GetFiles()~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~分类信息:未指定:( :)[],MethodInvocationException FullyQualifiedErrorId:IOException

有谁知道如何让压缩档案为UNC路径工作?

谢谢!

编辑:

这是当前的结果:(单斜杠实际上是双倍的,但是当我编辑以删除我公司的详细信息时会丢失)

Get-ChildItem:拒绝访问路径'\ server \ Home3 \ user \ Desktop' . 在C:\ windows \ system32 \ windowspowershell \ v1.0 \ Modules \ Microsoft.PowerShell.Archive \ Microsoft.PowerShell.Archive.psm1:663 char:20 $ dirContents = Get-ChildItem -LiteralPath $ sourceDirPath -Recurse ~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~分类信息:PermissionDenied: (\ server \ Home3 \ user \ Desktop:String)[Get-ChildItem],UnauthorizedAccessException FullyQualifiedErrorId:DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand Get-ChildItem:拒绝访问路径'\ server \ Home3 \ user \ Documents' . 在C:\ windows \ system32 \ windowspowershell \ v1.0 \ Modules \ Microsoft.PowerShell.Archive \ Microsoft.PowerShell.Archive.psm1:663 char:20 $ dirContents = Get-ChildItem -LiteralPath $ sourceDirPath -Recurse ~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~分类信息:PermissionDenied: (\ server \ Home3 \ user \ Documents:String)[Get-ChildItem],UnauthorizedAccessException FullyQualifiedErrorId:DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand Remove-Item:找不到路径'C:\ testzippowershell \ user.zip',因为它确实不存在 . 在C:\ windows \ system32 \ windowspowershell \ v1.0 \ Modules \ Microsoft.PowerShell.Archive \ Microsoft.PowerShell.Archive.psm1:233 char:21 ... Remove-Item -LiteralPath $ DestinationPath -Force -Recurse .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ CategoryInfo:ObjectNotFound:(C:\ testzippowershell \ user.zip:String)[Remove-Item],ItemNotFoundException FullyQualifiedErrorId:PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand以“0”调用“GetFiles”的异常“参数:”拒绝访问路径'\ server \ Home3 \ user \ Desktop' . “在C:\ windows \ system32 \ windowspowershell \ v1.0 \ Modules \ Microsoft.PowerShell.Archive \ Microsoft.PowerShell.Archive.psm1:677 char:13 $ files = $ currentContent.GetFiles()~~~~~~~~ 〜/ ~~~~~~~~~~~~~~~~~~~~~~~~分类信息:未指定:(:) [],MethodInvocationException FullyQualifiedErrorId:UnauthorizedAccessException

1 回答

  • 0

    我真蠢 .

    我测试的本地驱动器是我自己的 .

    我尝试了一个不同的,它没有任何问题 .

相关问题