PowerShell script not zipping on different computer
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
|
show 3 more comments
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
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 from7z
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 invoke7z.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
|
show 3 more comments
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
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
powershell scripting zip 7zip maxlength
edited Jan 7 at 23:20
techguy1029
asked Nov 20 '18 at 21:47
techguy1029techguy1029
6711
6711
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 from7z
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 invoke7z.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
|
show 3 more comments
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 from7z
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 invoke7z.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
|
show 3 more comments
1 Answer
1
active
oldest
votes
I was able to figure out what was causing this. The folder contained a lot of other folders inside of it. The -Recurse
made the script look in every folder, causing this problem. All I had to do was adjust the script to remove the -Recurse
and it worked.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I was able to figure out what was causing this. The folder contained a lot of other folders inside of it. The -Recurse
made the script look in every folder, causing this problem. All I had to do was adjust the script to remove the -Recurse
and it worked.
add a comment |
I was able to figure out what was causing this. The folder contained a lot of other folders inside of it. The -Recurse
made the script look in every folder, causing this problem. All I had to do was adjust the script to remove the -Recurse
and it worked.
add a comment |
I was able to figure out what was causing this. The folder contained a lot of other folders inside of it. The -Recurse
made the script look in every folder, causing this problem. All I had to do was adjust the script to remove the -Recurse
and it worked.
I was able to figure out what was causing this. The folder contained a lot of other folders inside of it. The -Recurse
made the script look in every folder, causing this problem. All I had to do was adjust the script to remove the -Recurse
and it worked.
answered Jan 21 at 23:45
techguy1029techguy1029
6711
6711
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 invoke7z.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