Cibb Posted January 30, 2017 Posted January 30, 2017 Hello, I'm new to autoit but had a question regarding creating a powershell script from inputs from a GUI. SPecifically this would involve reading the status of a checkbox or radio button then converting that to a line of code to be entered into a single powershell script that is created when the user clicks a button. I already have my basic UI setup and configured I need to perform a GUIctrlread then statement for the individual boxes. Is there an example that I haven't located that shows this task? I know it must be simple but I'm just not seeing the how.
Moderators JLogan3o13 Posted January 30, 2017 Moderators Posted January 30, 2017 You've already pretty much answered your own question. You would use GUICTrlRead to get the value of your input controls, and then simply pipe this to your PowerShell command. Something like this: #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 300, 200) $inpPC = GUICtrlCreateInput("Enter PC", 10, 10, 280, 30) $btnGo = GUICtrlCreateButton("Execute", 10, 150, 70, 40) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btnGo Run(@ComSpec & ' /k powershell.exe Get-ADComputer ' & GUICtrlRead($inpPC) & ' -Properties *') EndSwitch WEnd "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Cibb Posted January 30, 2017 Author Posted January 30, 2017 I'm wanting this to write this to a powershell script or create a powershell script not run it. Basically the GUI is a series of check boxes that if they check the box it will enter a line of powershell command into a script that will be created when they click the button.
Moderators JLogan3o13 Posted January 30, 2017 Moderators Posted January 30, 2017 So you would still follow the same methodology, and create your PS1 file. FileWriteLine(@ScriptDir & "\my.ps1", 'Get-ADComputer ' & GUICtrlRead($inpPC) & ' -Properties *') "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now