vmware-archive / webcommander

Powerful, flexible, intuitive and most importantly simple. That is what a real automation solution should be. No matter how complicated the task is, we'd like to turn it into a single click. Is that possible? Not without webcommander :)
MIT License
165 stars 47 forks source link

Hard Code a script in "Run Script Remotely" #165

Closed mikemast01 closed 7 years ago

mikemast01 commented 8 years ago

I can type in a script in web commander on the "Run Script Remotely" and it works fine. When I try to hard code that script into the command it will not finish and times out after the time out period.

I have tried to set the variable $script and remove the variable, I have tried to set it up as a default input to the string if nothing is entered on the web page, and still cannot get it to run.

Is there a way to hard code a script and not have to type it in each time?

9whirls commented 8 years ago

Please try to run the "run script remotely" script from powershell console. Define some simple command (such as "write-host test") to hardcode $script.

mikemast01 commented 8 years ago

Is there a way to hardcode it so I can have users run the script for the web site, with the script hardcoded and they dont have to put it in the site.

9whirls commented 8 years ago

Simply remove $script from parameter declaration. Line 71 t0 82 https://github.com/vmware/webcommander/blob/master/powershell/Windows/runScript.ps1#L82

mikemast01 commented 8 years ago

I tried to specify the $script in the run script remoely ps1. after removing the parameter. Right below where objects.ps1 is called, i put in $script= " command to run"

And when I try to run from webcommander it just spins until the timeout value. I then uncomment the parameter and put $script back in as a parameter value and it runs fine.

I am trying to figure out why I cant specify the $script in the ps1 file, but when it is a parameter it works fine.

Any Ideas.

9whirls commented 8 years ago

As I suggested in my first comment, run it in Powershell console directly and see what's the output there.

mikemast01 commented 8 years ago

Sorry Jerry, I have not gotten back to this due to my workload.

I will get back to it and let you know, please don’t close this out.

Mike Masters | VMware Administrator | Emerson | 8000 W. Florissant Ave. | St. Louis | MO | 63136 | USA T +1 314.553.2542 | F + 1 314.553.1491 | M +1 314.502.8914 CompTIA | A+ , Net + , Sec. + VMWare | VCP 3,4,5 VCAP5-DCA MCITP | 2008 SA/VA

From: Jerry Liu [mailto:notifications@github.com] Sent: Friday, May 13, 2016 10:44 AM To: vmware/webcommander webcommander@noreply.github.com Cc: Masters, Mike [CORP/US] Mike.Masters@Emerson.com; Author author@noreply.github.com Subject: Re: [vmware/webcommander] Hard Code a script in "Run Script Remotely" (#165)

Please try to run the "run script remotely" script from powershell console. Define some simple command (such as "write-host test") to hardcode $script.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHubhttps://github.com/vmware/webcommander/issues/165#issuecomment-219081306

mikemast01 commented 8 years ago

Ok I am finally back on this. So the command I want to run is ; Get-CimInstance -ClassName win32_OperatingSystem | select lastbootuptime

I can run in powershell on the server and in the " run script remotely" , when I manually put it in.. but when I hard code the command into the script , web commander just spins and I get no result.

[parameter( HelpMessage="Script to run" )] [string] $script="Get-CimInstance -ClassName win32_OperatingSystem | select lastbootuptime",

I am wanting to setup a script for users that will give them info about the server or multiple servers and not have to log into every server on any server to run the powershell command it will be already setup, and the first thing is the uptime details...

Thanks for any ideas on this,

Mike

mikemast01 commented 8 years ago

So if I leave this in the parameter for "script to run"

[parameter( HelpMessage="Script to run" )] [string]

$script="Get-CimInstance -ClassName win32_OperatingSystem | select lastbootuptime",

and I set the default type to powershell, and I run from powershell directly I get this and get a result.

PS C:\WebCommander\powershell\Windows> & '.\runScript - Copy.ps1'

cmdlet runScript - Copy.ps1 at command pipeline position 1 Supply values for the following parameters: (Type !? for Help.) vmName: evac.emrsn.org ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is an empty string. At C:\WebCommander\powershell\objects.ps1:1325 char:119

Success - connect to remote Windows machine 10.16.146.38 Success - run powershell script in VM

lastbootuptime PSComputerName RunspaceId


5/11/2016 11:06:05 AM 10.16.146.38 477728b1-b0f2-4e21-8f02-f29e0deb2cf7

When I run the same command thru web commander website it will just spin and time out.

9whirls commented 8 years ago

Is the script definition in one line or 2 lines? If 2, put it in 1 line and try again. If this still doesn't work, try $script="write-host test". Let me know the results.