Sign in to follow this  
Followers 0
PnoT

psexec and passing variables to the command line

6 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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)


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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.

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
Sign in to follow this  
Followers 0