PowerShell script not zipping on different computer












1















I have the following script for zipping old files:



# Zipping old files and sending them to a file on desktop if older than 60 days

Function Zip {
Param(
[Parameter(Mandatory)]
[string]$zipFile
,
[Parameter(Mandatory)]
[String]$toBeZipped
)
$null = & "C:Program Files7-Zip7z.exe" A -tzip $zipFile $toBeZipped
}

$Days = 60
$LastWrite = (Get-Date).Date.AddDays(-$Days)
$TargetFolder = "D:Testing*"

$Files = Get-Childitem $TargetFolder -Recurse |
Where-Object { $_.LastWriteTime -le $LastWrite } |
Select-Object -ExpandProperty Fullname

Zip "$($ENV:USERPROFILE)DesktopTEST.zip" $Files


I worked when I tested it on a VM and one physical machine.
However, when I tried it on a different computer, it failed.
This is what I got:



Program '7z.exe' failed to run: The filename or extension is too long
At C:UsersAdminDocumentszip help.ps1:23 char:9
+ $null = & "C:Program Files7-Zip7z.exe" A -tzip $zipFile $toBeZippe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
At C:UsersAdminDocumentszip help.ps1:23 char:1
+ $null = & "C:Program Files7-Zip7z.exe" A -tzip $zipFile $toBeZippe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) , ApplicationFailedEx
ception
+ FullyQualifiedErrorId : NativeCommandFailed


The script can't use 7-zip. The other computers had 7-Zip in the exact same file path so I am unsure of what my problem is. Any input will be appreciated.



Edit: I can confirm the error is because of the long file path. Tried my script on a file with shorter path and it worked just fine.










share|improve this question




















  • 1





    have you confirmed that the exe is in the expected location on the erroring system?

    – Lee_Dailey
    Nov 20 '18 at 21:52






  • 1





    then you need to add some output that shows what the $Vars in the call contain. it may be referring to the content of one of those $zipFile $toBeZippe variables.

    – Lee_Dailey
    Nov 20 '18 at 22:07






  • 1





    comment out the line that starts with $null = & "C:` and then add a line just after the $null = & "C:` line for each $Var that is in that command. that will output the values in those lines at that time.

    – Lee_Dailey
    Nov 20 '18 at 22:52






  • 3





    I can almost guarantee that the full file path of one of the files in $files is too long, and 7 zip can't archive it due to the file path length. Don't blame them, blame Windows. On the failing computer run $files | Measure-Object Length -Max and take a look at the length of the longest path, and let us know what it is.

    – TheMadTechnician
    Nov 21 '18 at 0:03






  • 1





    @TheMadTechnician: The puzzling thing is that if you provoke the path-too-long error manually, you get a different error message (a warning from 7z itself, "The parameter is incorrect"): 7z a t ('x' * 256). Similarly, if you exceed the max. command-line length, you get "The command line is too long": 7z a t ('x' * 8192). The actual error message suggests that PowerShell was fundamentally unable to invoke 7z.exe; the mystery is what path the error message relates to, as it can't be "C:Program Files7-Zip7z.exe". Alexis, is there remoting involved? How are you invoking your script?

    – mklement0
    Nov 22 '18 at 13:36


















1















I have the following script for zipping old files:



# Zipping old files and sending them to a file on desktop if older than 60 days

Function Zip {
Param(
[Parameter(Mandatory)]
[string]$zipFile
,
[Parameter(Mandatory)]
[String]$toBeZipped
)
$null = & "C:Program Files7-Zip7z.exe" A -tzip $zipFile $toBeZipped
}

$Days = 60
$LastWrite = (Get-Date).Date.AddDays(-$Days)
$TargetFolder = "D:Testing*"

$Files = Get-Childitem $TargetFolder -Recurse |
Where-Object { $_.LastWriteTime -le $LastWrite } |
Select-Object -ExpandProperty Fullname

Zip "$($ENV:USERPROFILE)DesktopTEST.zip" $Files


I worked when I tested it on a VM and one physical machine.
However, when I tried it on a different computer, it failed.
This is what I got:



Program '7z.exe' failed to run: The filename or extension is too long
At C:UsersAdminDocumentszip help.ps1:23 char:9
+ $null = & "C:Program Files7-Zip7z.exe" A -tzip $zipFile $toBeZippe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
At C:UsersAdminDocumentszip help.ps1:23 char:1
+ $null = & "C:Program Files7-Zip7z.exe" A -tzip $zipFile $toBeZippe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) , ApplicationFailedEx
ception
+ FullyQualifiedErrorId : NativeCommandFailed


The script can't use 7-zip. The other computers had 7-Zip in the exact same file path so I am unsure of what my problem is. Any input will be appreciated.



Edit: I can confirm the error is because of the long file path. Tried my script on a file with shorter path and it worked just fine.










share|improve this question




















  • 1





    have you confirmed that the exe is in the expected location on the erroring system?

    – Lee_Dailey
    Nov 20 '18 at 21:52






  • 1





    then you need to add some output that shows what the $Vars in the call contain. it may be referring to the content of one of those $zipFile $toBeZippe variables.

    – Lee_Dailey
    Nov 20 '18 at 22:07






  • 1





    comment out the line that starts with $null = & "C:` and then add a line just after the $null = & "C:` line for each $Var that is in that command. that will output the values in those lines at that time.

    – Lee_Dailey
    Nov 20 '18 at 22:52






  • 3





    I can almost guarantee that the full file path of one of the files in $files is too long, and 7 zip can't archive it due to the file path length. Don't blame them, blame Windows. On the failing computer run $files | Measure-Object Length -Max and take a look at the length of the longest path, and let us know what it is.

    – TheMadTechnician
    Nov 21 '18 at 0:03






  • 1





    @TheMadTechnician: The puzzling thing is that if you provoke the path-too-long error manually, you get a different error message (a warning from 7z itself, "The parameter is incorrect"): 7z a t ('x' * 256). Similarly, if you exceed the max. command-line length, you get "The command line is too long": 7z a t ('x' * 8192). The actual error message suggests that PowerShell was fundamentally unable to invoke 7z.exe; the mystery is what path the error message relates to, as it can't be "C:Program Files7-Zip7z.exe". Alexis, is there remoting involved? How are you invoking your script?

    – mklement0
    Nov 22 '18 at 13:36
















1












1








1








I have the following script for zipping old files:



# Zipping old files and sending them to a file on desktop if older than 60 days

Function Zip {
Param(
[Parameter(Mandatory)]
[string]$zipFile
,
[Parameter(Mandatory)]
[String]$toBeZipped
)
$null = & "C:Program Files7-Zip7z.exe" A -tzip $zipFile $toBeZipped
}

$Days = 60
$LastWrite = (Get-Date).Date.AddDays(-$Days)
$TargetFolder = "D:Testing*"

$Files = Get-Childitem $TargetFolder -Recurse |
Where-Object { $_.LastWriteTime -le $LastWrite } |
Select-Object -ExpandProperty Fullname

Zip "$($ENV:USERPROFILE)DesktopTEST.zip" $Files


I worked when I tested it on a VM and one physical machine.
However, when I tried it on a different computer, it failed.
This is what I got:



Program '7z.exe' failed to run: The filename or extension is too long
At C:UsersAdminDocumentszip help.ps1:23 char:9
+ $null = & "C:Program Files7-Zip7z.exe" A -tzip $zipFile $toBeZippe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
At C:UsersAdminDocumentszip help.ps1:23 char:1
+ $null = & "C:Program Files7-Zip7z.exe" A -tzip $zipFile $toBeZippe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) , ApplicationFailedEx
ception
+ FullyQualifiedErrorId : NativeCommandFailed


The script can't use 7-zip. The other computers had 7-Zip in the exact same file path so I am unsure of what my problem is. Any input will be appreciated.



Edit: I can confirm the error is because of the long file path. Tried my script on a file with shorter path and it worked just fine.










share|improve this question
















I have the following script for zipping old files:



# Zipping old files and sending them to a file on desktop if older than 60 days

Function Zip {
Param(
[Parameter(Mandatory)]
[string]$zipFile
,
[Parameter(Mandatory)]
[String]$toBeZipped
)
$null = & "C:Program Files7-Zip7z.exe" A -tzip $zipFile $toBeZipped
}

$Days = 60
$LastWrite = (Get-Date).Date.AddDays(-$Days)
$TargetFolder = "D:Testing*"

$Files = Get-Childitem $TargetFolder -Recurse |
Where-Object { $_.LastWriteTime -le $LastWrite } |
Select-Object -ExpandProperty Fullname

Zip "$($ENV:USERPROFILE)DesktopTEST.zip" $Files


I worked when I tested it on a VM and one physical machine.
However, when I tried it on a different computer, it failed.
This is what I got:



Program '7z.exe' failed to run: The filename or extension is too long
At C:UsersAdminDocumentszip help.ps1:23 char:9
+ $null = & "C:Program Files7-Zip7z.exe" A -tzip $zipFile $toBeZippe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
At C:UsersAdminDocumentszip help.ps1:23 char:1
+ $null = & "C:Program Files7-Zip7z.exe" A -tzip $zipFile $toBeZippe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) , ApplicationFailedEx
ception
+ FullyQualifiedErrorId : NativeCommandFailed


The script can't use 7-zip. The other computers had 7-Zip in the exact same file path so I am unsure of what my problem is. Any input will be appreciated.



Edit: I can confirm the error is because of the long file path. Tried my script on a file with shorter path and it worked just fine.







powershell scripting zip 7zip maxlength






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 7 at 23:20







techguy1029

















asked Nov 20 '18 at 21:47









techguy1029techguy1029

4410




4410








  • 1





    have you confirmed that the exe is in the expected location on the erroring system?

    – Lee_Dailey
    Nov 20 '18 at 21:52






  • 1





    then you need to add some output that shows what the $Vars in the call contain. it may be referring to the content of one of those $zipFile $toBeZippe variables.

    – Lee_Dailey
    Nov 20 '18 at 22:07






  • 1





    comment out the line that starts with $null = & "C:` and then add a line just after the $null = & "C:` line for each $Var that is in that command. that will output the values in those lines at that time.

    – Lee_Dailey
    Nov 20 '18 at 22:52






  • 3





    I can almost guarantee that the full file path of one of the files in $files is too long, and 7 zip can't archive it due to the file path length. Don't blame them, blame Windows. On the failing computer run $files | Measure-Object Length -Max and take a look at the length of the longest path, and let us know what it is.

    – TheMadTechnician
    Nov 21 '18 at 0:03






  • 1





    @TheMadTechnician: The puzzling thing is that if you provoke the path-too-long error manually, you get a different error message (a warning from 7z itself, "The parameter is incorrect"): 7z a t ('x' * 256). Similarly, if you exceed the max. command-line length, you get "The command line is too long": 7z a t ('x' * 8192). The actual error message suggests that PowerShell was fundamentally unable to invoke 7z.exe; the mystery is what path the error message relates to, as it can't be "C:Program Files7-Zip7z.exe". Alexis, is there remoting involved? How are you invoking your script?

    – mklement0
    Nov 22 '18 at 13:36
















  • 1





    have you confirmed that the exe is in the expected location on the erroring system?

    – Lee_Dailey
    Nov 20 '18 at 21:52






  • 1





    then you need to add some output that shows what the $Vars in the call contain. it may be referring to the content of one of those $zipFile $toBeZippe variables.

    – Lee_Dailey
    Nov 20 '18 at 22:07






  • 1





    comment out the line that starts with $null = & "C:` and then add a line just after the $null = & "C:` line for each $Var that is in that command. that will output the values in those lines at that time.

    – Lee_Dailey
    Nov 20 '18 at 22:52






  • 3





    I can almost guarantee that the full file path of one of the files in $files is too long, and 7 zip can't archive it due to the file path length. Don't blame them, blame Windows. On the failing computer run $files | Measure-Object Length -Max and take a look at the length of the longest path, and let us know what it is.

    – TheMadTechnician
    Nov 21 '18 at 0:03






  • 1





    @TheMadTechnician: The puzzling thing is that if you provoke the path-too-long error manually, you get a different error message (a warning from 7z itself, "The parameter is incorrect"): 7z a t ('x' * 256). Similarly, if you exceed the max. command-line length, you get "The command line is too long": 7z a t ('x' * 8192). The actual error message suggests that PowerShell was fundamentally unable to invoke 7z.exe; the mystery is what path the error message relates to, as it can't be "C:Program Files7-Zip7z.exe". Alexis, is there remoting involved? How are you invoking your script?

    – mklement0
    Nov 22 '18 at 13:36










1




1





have you confirmed that the exe is in the expected location on the erroring system?

– Lee_Dailey
Nov 20 '18 at 21:52





have you confirmed that the exe is in the expected location on the erroring system?

– Lee_Dailey
Nov 20 '18 at 21:52




1




1





then you need to add some output that shows what the $Vars in the call contain. it may be referring to the content of one of those $zipFile $toBeZippe variables.

– Lee_Dailey
Nov 20 '18 at 22:07





then you need to add some output that shows what the $Vars in the call contain. it may be referring to the content of one of those $zipFile $toBeZippe variables.

– Lee_Dailey
Nov 20 '18 at 22:07




1




1





comment out the line that starts with $null = & "C:` and then add a line just after the $null = & "C:` line for each $Var that is in that command. that will output the values in those lines at that time.

– Lee_Dailey
Nov 20 '18 at 22:52





comment out the line that starts with $null = & "C:` and then add a line just after the $null = & "C:` line for each $Var that is in that command. that will output the values in those lines at that time.

– Lee_Dailey
Nov 20 '18 at 22:52




3




3





I can almost guarantee that the full file path of one of the files in $files is too long, and 7 zip can't archive it due to the file path length. Don't blame them, blame Windows. On the failing computer run $files | Measure-Object Length -Max and take a look at the length of the longest path, and let us know what it is.

– TheMadTechnician
Nov 21 '18 at 0:03





I can almost guarantee that the full file path of one of the files in $files is too long, and 7 zip can't archive it due to the file path length. Don't blame them, blame Windows. On the failing computer run $files | Measure-Object Length -Max and take a look at the length of the longest path, and let us know what it is.

– TheMadTechnician
Nov 21 '18 at 0:03




1




1





@TheMadTechnician: The puzzling thing is that if you provoke the path-too-long error manually, you get a different error message (a warning from 7z itself, "The parameter is incorrect"): 7z a t ('x' * 256). Similarly, if you exceed the max. command-line length, you get "The command line is too long": 7z a t ('x' * 8192). The actual error message suggests that PowerShell was fundamentally unable to invoke 7z.exe; the mystery is what path the error message relates to, as it can't be "C:Program Files7-Zip7z.exe". Alexis, is there remoting involved? How are you invoking your script?

– mklement0
Nov 22 '18 at 13:36







@TheMadTechnician: The puzzling thing is that if you provoke the path-too-long error manually, you get a different error message (a warning from 7z itself, "The parameter is incorrect"): 7z a t ('x' * 256). Similarly, if you exceed the max. command-line length, you get "The command line is too long": 7z a t ('x' * 8192). The actual error message suggests that PowerShell was fundamentally unable to invoke 7z.exe; the mystery is what path the error message relates to, as it can't be "C:Program Files7-Zip7z.exe". Alexis, is there remoting involved? How are you invoking your script?

– mklement0
Nov 22 '18 at 13:36














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402065%2fpowershell-script-not-zipping-on-different-computer%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402065%2fpowershell-script-not-zipping-on-different-computer%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?