Jump to content

psexec and passing variables to the command line


Recommended Posts

I'm trying to get this script to run a powershell command on a remote server so i can give executive admins in our company an easy way to setup anyone with out of office.

I believe I'm passing the input variables wrong at the end because i have verified the script launches the powershell.exe on the remote system.

The arguments for the powershell script are:

PowerShell.exe <pathToScript>\set-OOf.ps1 <Primary SMTP Address of User> OOf Message

(notice the ' ' on the last argument)

Here is my script so far...

$email = InputBox("Out of Office Tool", "Email address of employee?")

$message = InputBox("Out of Office Tool", "Message to be displayed in Out of Office Message?")

run("psexec \\servername -d -u username -p password -w c:\oofscript\ ""powershell.exe c:\oofscript\set-oof.ps1"" & $email & $message")

Link to comment
Share on other sites

  • Developers

run("psexec \\servername -d -u username -p password -w c:\oofscript\ ""powershell.exe c:\oofscript\set-oof.ps1"" " & $email & " '"  & $message & "'")

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

run("psexec \\servername -d -u username -p password -w c:\oofscript\ ""powershell.exe c:\oofscript\set-oof.ps1"" " & $email & " '"  & $message & "'")
I ran the code that you've posted but now the powershell.exe is not showing up on the remote server as a process anymore so it's acting like no execution is being done.
Link to comment
Share on other sites

  • Developers

I didn't check your whole commandline before but it looks like you had a double quote at the wrong place. Try this version:

run("psexec \\servername -d -u username -p password -w c:\oofscript\powershell.exe ""c:\oofscript\set-oof.ps1"" " & $email & " '"  & $message & "'")
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

To check if the real command is looking correct you could also run something like this from SciTE:

Consolewrite("psexec \\servername -d -u username -p password -w c:\oofscript\powershell.exe ""c:\oofscript\set-oof.ps1"" " & $email & " '" & $message & "'")

ConsoleWrite(@crlf)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I didn't check your whole commandline before but it looks like you had a double quote at the wrong place. Try this version:

run("psexec \\servername -d -u username -p password -w c:\oofscript\powershell.exe ""c:\oofscript\set-oof.ps1"" " & $email & " '"  & $message & "'")
That fixed things for me!

Thank you very much for the assistance and super quick response. You've gotta love a forum where a developer takes the time out of his/her busy schedule to lend a helping hand.

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...