I have the following components:
- A windows server 2008 R2 box
- An administrator account (mine)
- A service account on the domain that is an Administrator of the box
- An installation of Putty (including plink for command line and Pageant as the ssh public key generation)
- A text file for commands to be used during an SSH session
- A powershell script that runs plink which uses Start-Process to invoke plink with command lines that tell it to use Ageant for the PuTTy connection and commands.txt for the command.
- A scheduled task that runs as my user account
Eventually, to get the scheduled task to run as a service account, which calls powershell as the service account, which runs the process and carries out the ssh commands.
- When I run this script from a powershell command prompt as my user account, it runs.
- When I run this script from a scheduled task as my user account, with the highest permissions, and tell it to save my credentials, it "doesn't run".
- By "doesn't run", it mean it appears to spawn an instance of plink.exe, which is where I think the problem is occurring (something hanging that I can't see on the console).
- Anybody have an overall-solution that's a little more elegant but uses the same or similar tools?
- Should my powershell script instead invoke cmd.exe so that I can capture the stdout into my log file at least?
In case it helps:
#Starts the vcenter2 server. #if the server is already started, it will tell you so. #Stop an error from occurring when a transcript is already stopped $ErrorActionPreference="SilentlyContinue" Stop-Transcript | out-null #Reset the error level before starting the transcript $ErrorActionPreference="Continue" Start-Transcript -path C:\Scripts\logs\StartTheVCenter2Server.log -append #Run plink and reference the commands file to start up the server Start-Process "C:\Program Files (x86)\PuTTY\plink.exe" -Argumentlist "-agent -m C:\Scripts\idrac_powerup_commands.txt root@[servernameredacted]" -wait -RedirectStandardOutput "C:\Scripts\logs\plinklog.log" #Clean-up Stop-Transcript
Thoughts? I'll likely play around with Invoke-Command to see if I can get it redirect the output into my log at least.