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.
powershell scripting zip 7zip maxlength
|
show 2 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.
powershell scripting zip 7zip maxlength
have you confirmed that the exe is in the expected location on the erroring system?
– Lee_Dailey
Nov 20 at 21:52
Yep, same place as other systems
– Alexis
Nov 20 at 21:54
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 at 22:07
Ok. I'm a noob at this. Can I get an example of what that would look like?
– Alexis
Nov 20 at 22:13
2
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 at 0:03
|
show 2 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.
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.
powershell scripting zip 7zip maxlength
powershell scripting zip 7zip maxlength
edited Nov 20 at 23:40
mklement0
126k20239267
126k20239267
asked Nov 20 at 21:47
Alexis
4010
4010
have you confirmed that the exe is in the expected location on the erroring system?
– Lee_Dailey
Nov 20 at 21:52
Yep, same place as other systems
– Alexis
Nov 20 at 21:54
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 at 22:07
Ok. I'm a noob at this. Can I get an example of what that would look like?
– Alexis
Nov 20 at 22:13
2
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 at 0:03
|
show 2 more comments
have you confirmed that the exe is in the expected location on the erroring system?
– Lee_Dailey
Nov 20 at 21:52
Yep, same place as other systems
– Alexis
Nov 20 at 21:54
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 at 22:07
Ok. I'm a noob at this. Can I get an example of what that would look like?
– Alexis
Nov 20 at 22:13
2
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 at 0:03
have you confirmed that the exe is in the expected location on the erroring system?
– Lee_Dailey
Nov 20 at 21:52
have you confirmed that the exe is in the expected location on the erroring system?
– Lee_Dailey
Nov 20 at 21:52
Yep, same place as other systems
– Alexis
Nov 20 at 21:54
Yep, same place as other systems
– Alexis
Nov 20 at 21:54
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 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 at 22:07
Ok. I'm a noob at this. Can I get an example of what that would look like?
– Alexis
Nov 20 at 22:13
Ok. I'm a noob at this. Can I get an example of what that would look like?
– Alexis
Nov 20 at 22:13
2
2
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 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 at 0:03
|
show 2 more comments
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
});
}
});
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
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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
have you confirmed that the exe is in the expected location on the erroring system?
– Lee_Dailey
Nov 20 at 21:52
Yep, same place as other systems
– Alexis
Nov 20 at 21:54
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 at 22:07
Ok. I'm a noob at this. Can I get an example of what that would look like?
– Alexis
Nov 20 at 22:13
2
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 at 0:03