2017-10-04 99 views
0

我试图制作一个脚本,它将自动在网络驱动器上找到正确的文件夹。这些是我们用户的家庭文件夹。无法压缩 - 从UNC路径存档

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

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

我试着运行提升的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 : The specified network name is no longer available. At C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:663 char:20 + $dirContents = Get-ChildItem -LiteralPath $sourceDirPath -Recurse + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ReadError: (\server\Home3\user\Desktop:String) [Get-ChildItem], IOException + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand Get-ChildItem : The specified network name is no longer available. At C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:663 char:20 + $dirContents = Get-ChildItem -LiteralPath $sourceDirPath -Recurse + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ReadError: (\server\Home3\user\Documents:String) [Get-ChildItem], IOException + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand Remove-Item : Cannot find path 'C:\testzippowershell\user.zip' because it does not exist. At 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 Exception calling "GetFiles" with "0" argument(s): "The specified network name is no longer available. " At C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:677 char:13 + $files = $currentContent.GetFiles() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : IOException

有谁知道如何得到压缩存档的UNC路径的工作?

谢谢!

编辑:

这是当前结果: (单斜杠实际上是双,但是当我编辑从我公司删除细节迷路)

Get-ChildItem : Access to the path '\server\Home3\user\Desktop' is denied. At C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:663 char:20 + $dirContents = Get-ChildItem -LiteralPath $sourceDirPath -Recurse + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (\server\Home3\user\Desktop:String) [Get-ChildItem], UnauthorizedAccessException + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand Get-ChildItem : Access to the path '\server\Home3\user\Documents' is denied. At C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:663 char:20 + $dirContents = Get-ChildItem -LiteralPath $sourceDirPath -Recurse + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (\server\Home3\user\Documents:String) [Get-ChildItem], UnauthorizedAccessException + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand Remove-Item : Cannot find path 'C:\testzippowershell\user.zip' because it does not exist. At 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
Exception calling "GetFiles" with "0" argument(s): "Access to the path '\server\Home3\user\Desktop' is denied." At C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:677 char:13 + $files = $currentContent.GetFiles() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : UnauthorizedAccessException

+0

对我来说,我可以压缩unc路径中的文件。 test-path -path $ source'的结果是什么? – guiwhatsthat

+0

由于错误显示为'\ server \ Home3 \ user \ Desktop',看起来您从UNC路径的开头缺少一个斜杠,但我不确定这是怎么发生的!也许尝试在每条路径周围放置单引号? –

+0

如果我使用-path而不是-literalpath,我得到这些错误: Get-ChildItem:访问路径'\\ server \ Home3 \ user \ Desktop'被拒绝。 –

回答

0

我是愚蠢的。

我测试的homedrive是我自己的。

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