I'm trying to make a script that will automaticly find the correct folder on a network drive. These are our users' homefolders.
I want to zip the specified folder and place it somewhere else.
I keep getting an error that access is denied on the network drive when the zipping proces start.
I tried running elevated powershell, but the same error occurs. Here is the script I made:
[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
These are the resulting errors:
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
Does anyone know how to get the compress-archive working for a UNC path?
Thanks!
Edit:
This is the current result: (The single slash is actually double, but get lost when I edit to remove details from my company)
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
\server\Home3\user\Desktop
, I'm not sure how this is happening though! maybe try putting single quotes around each path? – James C.