Jump to content
Au3Builder

im unable to successfuly run a powershell command from AutoIt

Recommended Posts

Au3Builder

Any idea what's wrong with this? I want to zip a folder of mine.

Run('powershell.exe Compress-Archive -Path "C:\Users\GOD\Desktop\New Folder" -DestinationPath "test.zip"')

Edited by Au3Builder

Share this post


Link to post
Share on other sites
Au3Builder

I highly doubt it. Windows PowerShell itself compresses the folder without errors. Only Autoit doesn't and i'm using the previous version.

Edited by Au3Builder

Share this post


Link to post
Share on other sites
jdelaney

If you run the exact command in the run window, does it execute fully?  windowskey +r

  • Like 1

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Au3Builder
9 minutes ago, jdelaney said:

If you run the exact command in the run window, does it execute fully?  windowskey +r

Nope .In short, I have accomplished the task only in two scenarios.

a) I copy & paste the exact command to Windows Powershell console.

b.) I create a powershell script and I run it with powershell.

Edited by Au3Builder

Share this post


Link to post
Share on other sites
jdelaney

Ok, good. I'm sure someone could help with this issue, but it's not an autoit issue. Maybe use the -command parameter?  else you have to keep googleing, or go to a powershell forum

Edited by jdelaney
  • Like 1

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Earthshine

Use 7zip for applications. They have an exe you can use from installers and what not. I pack it with my installers to un  zip my shit. But it can be used to zip stuff. Are use it to create my build archives

Edited by Earthshine
  • Like 1

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
JLogan3o13

If it is not working from the run command, as was stated, sounds like a PowerShell issue. Perhaps you should ask on a PowerShell forum.

Edited by JLogan3o13
  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Au3Builder
1 hour ago, JLogan3o13 said:

If it is not working from the run command, as was stated, sounds like a PowerShell issue. Perhaps you should ask on a PowerShell forum.

I bet lots of people use AutoIt in conjuction with PowerShell. sooner or later somebody posts me a solution here.nonetheless many thanks to you, Earthshine and Jdelaney.

Edited by Au3Builder

Share this post


Link to post
Share on other sites
Subz

It worked for me under these conditions:
Changed the double quotes in your code above to single quotes
Changed the single quotes in your code above to double quotes
Use full path for -DestinationPath
Or
Use WorkingDir

Run("powershell.exe Compress-Archive -Path 'C:\Users\GOD\Desktop\New Folder' -DestinationPath 'C:\Users\GOD\Desktop\test.zip'")

Or

Run("powershell.exe Compress-Archive -Path 'C:\Users\GOD\Desktop\New Folder' -DestinationPath 'test.zip'", 'C:\Users\GOD\Desktop')

 

Share this post


Link to post
Share on other sites
iamtheky

and anytime you are dealing with quoted things within a quoted string, you can always set them to a var to ensure that quotes are not the issue.

e.g.

$spath = "'C:\Users\GOD\Desktop\New Folder'"

$dpath = "'C:\Users\GOD\Desktop\test.zip'"

Run("powershell Compress-Archive -Path " & $spath & " -DestinationPath " & $dpath)

 

Edited by iamtheky
  • Like 2

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
Au3Builder
7 hours ago, Subz said:

 

Run("powershell.exe Compress-Archive -Path 'C:\Users\GOD\Desktop\New Folder' -DestinationPath 'C:\Users\GOD\Desktop\test.zip'")

 

Thank you! I can't explain why but putting double & single quotes in the right order as mentioned above solved the issue .

it would be great If somebody could elaborate on this so I knew what the point is.

Edited by Au3Builder

Share this post


Link to post
Share on other sites
Subz

If you run the code in Cmd, you'll see the error, it strips the quotes unless you use single quotes or escape the double quotes, its a fairly common issue when running PowerShell.exe from command line.

Compress-Archive : A positional parameter cannot be found that accepts argument 'Folder'.
At line:1 char:1
+ Compress-Archive -Path C:\Users\GOD\Desktop\New Folder -DestinationPath test.zip
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Compress-Archive], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Compress-Archive

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×