Decipher powershell script line

Hello,

I’m occassionally working with Powershell but am far from experienced.

Can someone decipher this combined powershell line?

powershell -command “& {compress-archive ‘localuse.xml’ -destinationPath ‘%AppData%\Test\temp.zip’}”

The command is scripted within a CMD script. But it also fails when I run it directly in powershell.

It fails with the error that “compress-archive” is not a recognized as the name of a cmdlet, function, script file or operable program.

responding from mobile:
It calls the PowerShell executable with the “command” argument specifying what commands(s) to run within the Powershell session.
The ampersand is the call operator and basically says to run everything within the curly braces.
Compress-archive is used for creating a zip archive. Based on the error message you’ve received my guess is that you don’t have Windows PowerShell v5.1 or newer which means you’re probably on something older than Windows 10.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.