Link to home
Start Free TrialLog in
Avatar of emkayd
emkayd

asked on

Embedding Powershell in to Windows Forms

I'm writing a small GUI based (windows form) powershell tool for my team and my own use based on things that we repetitively do every day (like check if a service is running, start/stop/restart, check for amt of memory, cpu spikes, check for win updates, if C drv is really full etc).
So basically I have a form with a bunch of buttons with some logic (check if they have entered the right hostname, or if the service exists or not, displays/starts/stops services from multiple machines etc). I'm trying to display at least the output of these cmdlets in a textbox or richtextbox or datagridview, but can't seem to figure out how or which to use...
For example get-service (either all or one particular service or wild-card) should be shown in the richtextbox, right now i'm just using popup windows and out-gridview.

Even better (i understand this must be very hard, I saw PowerShellTunnel) will be to be able to embed Powershell window inside a win form, is that even possible? Basically capture console screen and display it...
Any useful/alternate ideas or suggestions, examples, links, anything at all on this topic will help me move forward with this project....thanks for your help in advance..
Avatar of Kamaraj Subramanian
Kamaraj Subramanian
Flag of Singapore image

Avatar of emkayd
emkayd

ASKER

Thanks for the reply, but I don't understand how that thread is relevant to what I have asked for...
are you creating a form ( using vb.net ? )

how you are creating form ?
Avatar of emkayd

ASKER

I'm using Primal Forms to generate my GUI code, but before i realized there was a free community version of Primal Forms i did write the code without any 'visual' guide. But to answer your question, no i don't believe that is VB.NET code.
It is Powershell code which has ability to call .NET libraries to create GUI.
Avatar of emkayd

ASKER

Ok, since nobody has really answered my question, I think I might have asked it in a very confusing way. Let me attempt to make it a little clear -
I was hoping to get some insight/help/suggestion on the following -

1. How to format the result of this (with a title based on computernames) to show in a richtexbox or datagridview in a windows form (this is inside a 'for' loop)---> Get-WmiObject -class win32_service -computername $x[$y] -credential $cred | Select DisplayName, Name, State, Status, StartMode | Sort-Object Displayname |

2. Is it possible to have a username and password (not visible) Textboxes in the form and use those values from there everytime i use $cred? Right now $cred = Get-Credential, it's popping a challenge window. I have ask for credentials a lot of times because our environment is such, we have multiple domains and can't use one domain or service account for all.

3. A way to capture some of the errors that show up in the console right now, for instance, if the credentials entered doesn't have admin rights or if the user entered the wrong password etc.

Please let me know if you have any questions or need screenshots of what i have current to understand better. Thank you very much in advance.
Avatar of emkayd

ASKER

Really? Nobody can even attempt at answering some of the questions I have?
Avatar of emkayd

ASKER

Does anyone have any ideas about question no. 2 (to get admin credentials via win forms, basically type once and leave it there and all button clicks will get their $credential from those 2 Textboxes, instead of getting prompted every time)? I have figured out Q#1.
ASKER CERTIFIED SOLUTION
Avatar of Brent Challis
Brent Challis
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
EMKAYD,

I was creating a form in Powershell using PrimalForms and am also a member of EE and came across your post. Here are some things I came across.

Advanced Cred Function for storing passwords with Powershell on disk, Posted 5 days ago...

http://poshcode.org/3532

This link is more of MS general explanation of storing Cred usernames and passwwords to disk.

http://technet.microsoft.com/en-us/magazine/ff714574.aspx

-R3c0n