2017-10-04 101 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是我自己的。

我嘗試了一個不同的,它沒有任何問題的工作。