1

How to run the below command in PowerShell. The below command will prompt for a password and user needs to enter it. I want to automate it.

mxexport [ -f <zip file name> ]

I tried saving password in a file and run the below script in PowerShell:

$password = get-content C:\cred.txt | convertto-securestring
$pass=[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
& 'C:\Program Files\XX\XX\bin\mxexport.exe' -f file.zip, -p $pass

But I am getting the below Error:

mxexport.exe'
+              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Error while getting password from User.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
2
  • Do you get meaningful values for $password and $pass? Are you sure are calling mxexport with the correct value? Have you tried calling mxexport with a hard-coded value for $pass? Commented Jun 13, 2016 at 5:53
  • I just found out, mxexport accepts only one option called -f filename. But It is prompting for a password when I press enter after running a command mxexport.exe -f filename. How you to get the password from a file and execute the command without prompting fora password to enter. Commented Jun 13, 2016 at 7:11

1 Answer 1

2

You are using single quotes, therefore the $pass variable doesn't get resolved. You also don't need to wrap the arguments within quotes, just use:

& "C:\Program Files\XX\XX\bin\mxexport.exe" -p $pass

Edit to your comment

Try to pass the parameters using splatting:

$arguments = @("-f file.zip", "-p $pass")
& "C:\Program Files\XX\XX\bin\mxexport.exe" @arguments
Sign up to request clarification or add additional context in comments.

7 Comments

Sorry my bad. mxexport has only one option. i.e Filename. But It is asking for a Password. Below is the error I am getting. CategoryInfo : NotSpecified: (Error while getting password from User.:String)
Sorry for the confusuion. I just edited my question. mxexport.exe has only one option that will accept filename, If I give password as another parameter, It is not accepting. But whenever we give enter after mxexport.exe, Its prompting for a password. So I need my script to get the password from file instead of user input.
Ensure you $pass contains the password. Then try to pass the parameters using splatting (see me edit)
nope.Not working. I cant pass the password as parameter.
Okay, my last attempt would be to pass the parameter plain (without loading it from the file).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.