2017-10-04 10 views
0

J'essaie de créer un script qui trouvera automatiquement le bon dossier sur un lecteur réseau. Ce sont les homefolders de nos utilisateurs.Impossible de compresser - Archive à partir du chemin UNC

Je veux compresser le dossier spécifié et le placer ailleurs.

Je continue d'obtenir une erreur indiquant que l'accès est refusé sur le lecteur réseau lorsque le processus de compression démarre.

J'ai essayé d'exécuter powershell élevé, mais la même erreur se produit. Voici le script que je fait:

[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 

Ce sont les erreurs résultant:

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

Est-ce que quelqu'un sait comment obtenir le compress-archives travaillant pour un chemin UNC?

Merci!

Edit:

Ceci est le résultat courant: (La barre oblique est en fait double, mais se perdre quand je modifier pour supprimer les détails de mon entreprise)

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

Pour moi son fonctionnement, je peux compresser des fichiers d'un unc-path. quel est le résultat de test-path -path $ source'? – guiwhatsthat

+0

Il semblerait qu'il vous manque une barre oblique au début de votre chemin d'accès UNC, car l'erreur indique '\ server \ Home3 \ user \ Desktop', je ne sais pas comment cela se passe! peut-être essayer de mettre des guillemets simples autour de chaque chemin? –

+0

Si j'utilise -path au lieu de -literalpath, j'obtiens ces erreurs: Get-ChildItem: L'accès au chemin '\\ serveur \ Home3 \ user \ Desktop' est refusé. –

Répondre

0

j'étais stupide.

Le homedrive que je testais était le mien.

J'ai essayé avec un différent et cela fonctionnait sans aucun problème.