Jump to content

im unable to successfuly run a powershell command from AutoIt


Recommended Posts

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
Link to comment
Share on other sites

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
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.
Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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')

 

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...