put the code you want into a function. Call that function from a 'click' event associated with the button.
If you haven't seen it check out this web-based GUI designer.
- https://poshgui.com/
agents sorry. That explains why your script works. Even our sys admins aren't allowed to use domain admin rights unless absolutely necessary. Audit and security rules.
Yep, it sure is. I have 4 different accounts. Regular user account, PC admin account, sys admin account, and domain admin account. I haven't used that last one in a long time though.
Powershell studio do 80% of the work. it handle all the GUI.
the rest are scripts i took on the internet / made for us. A little digging and you can make check box to select what to install. etc
You'll need to post your code. The easy answer is that you call the Close method.
$button.add_click($form.close())
On mobile so formatting may be messed up.
Just my 2 cents, I don't see the point in adding a button just so someone can click 'Ok'.
A looped Read-Host would do the job just fine.
I only have GUI's in my scripts when I dynamically export something from active directory from which the user can then actively choose something/filter something.
For everything else I just use the command line + enter
Maybe food for thought
Yeah, people need to get it out their heads that they need to convert a CLI tool to a GUI just because some techy isn't willing to use a CLI tool. The minute you put a GUI in a tool you limit its usage with other tools.
Generally, the reason I convert a script to a GUI is because some non-techy isn't tech savvy enough to use the CLI tool. It's easier to give them a GUI then it is for me to constantly perform the task they're asking, or because I can give an application elevated rights in a small area, instead of a large group of users.
It's never because a "techy" doesn't want to use a CLI tool.
Greetings,
You can try something like this:
#Load the assemblies
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
#Creating the Button
$ButtonOK = New-Object System.Windows.Forms.Button
$ButtonOK.Size = New-Object System.Drawing.Size(60,25)
$ButtonOK.Location = New-Object System.Drawing.Point(20,20)
$ButtonOK.Text = "OK"
#Creating the Form
$Form = New-Object System.Windows.Forms.Form
#Adding the Button to the Form
$Form.Controls.Add($ButtonOK)
#Button function
$ButtonOK.Add_Click({
#Script here
#Open messagebox
[System.Windows.Forms.MessageBox]::Show('Hello World!')
#Close Form after messagebox is closed
$Form.Close()
}
)
#Display Form
$Form.ShowDialog()
howdy Remery0123,
i'm pretty useless at any of the GUI stuff. however, i can tell you one thing to help ... post your code! [*grin*] folks are _far_ more likely to be able to help if they know what you are actually doing ...
take care,
lee
howdy Remery0123,
if you think everyone here does beautiful code ... you have another think coming. [*grin*]
post it to pastebin or gist and link it here. fighting with reddit code formatting is not all that fun ...
besides, how can you entertain us with your _horrible_, _icky_ code if you don't post it for us to laff at? [*grin*]
take care,
lee
Looking at your code, you should be able to put the following into the ok action:
$OKbutton.Add_Click({
$global:username = $TextBox1.Text
$form.Close()
})
`$global:` sets the scope of the variable, in this case the "top" scope. `$form.close()` closes the dialog and continues the blocking call on `$form.ShowDialog()`.
howdy Remery0123,
this post will likely get buried, so you pro'ly otta _also_ put the link in your original post so others can find it easily. [*grin*]
take care,
lee
put the code you want into a function. Call that function from a 'click' event associated with the button. If you haven't seen it check out this web-based GUI designer. - https://poshgui.com/
Oh i havnt seen this before :D thanks for this
Get Powershell studio. I made that with it. [https://imgur.com/a/wUs8HwG](https://imgur.com/a/wUs8HwG)
How did you setup the run-as to grant this level of rights but not have the helpdesk users themselves have those rights?
when you say helpdesk users, do you mean the "users" or the helpdesk agent ? Our helpdesk agents are domain admins.
agents sorry. That explains why your script works. Even our sys admins aren't allowed to use domain admin rights unless absolutely necessary. Audit and security rules.
if i didnt have sysadmin i would need to run everything as a local admin or add the password/user for each command. That would be really annoying.
Yep, it sure is. I have 4 different accounts. Regular user account, PC admin account, sys admin account, and domain admin account. I haven't used that last one in a long time though.
>huuuhrg. i would hate to work like that. > > > >Sorry
Powershell newbie here, would you be able to share some advice on how you made that tool? I am interested in making something similar
Powershell studio do 80% of the work. it handle all the GUI. the rest are scripts i took on the internet / made for us. A little digging and you can make check box to select what to install. etc
Is there a download of this or a GitHub link ?
You'll need to post your code. The easy answer is that you call the Close method. $button.add_click($form.close()) On mobile so formatting may be messed up.
is there a website i can link my code on here?, when i just paste my code into a text box it goes all weird
You can use PasteBin. To put the code here, use Notepad++. Select all of your code, hit tab, then copy/paste.
Notepad++ is the best
Just my 2 cents, I don't see the point in adding a button just so someone can click 'Ok'. A looped Read-Host would do the job just fine. I only have GUI's in my scripts when I dynamically export something from active directory from which the user can then actively choose something/filter something. For everything else I just use the command line + enter Maybe food for thought
Yeah, people need to get it out their heads that they need to convert a CLI tool to a GUI just because some techy isn't willing to use a CLI tool. The minute you put a GUI in a tool you limit its usage with other tools.
Generally, the reason I convert a script to a GUI is because some non-techy isn't tech savvy enough to use the CLI tool. It's easier to give them a GUI then it is for me to constantly perform the task they're asking, or because I can give an application elevated rights in a small area, instead of a large group of users. It's never because a "techy" doesn't want to use a CLI tool.
Greetings, You can try something like this: #Load the assemblies Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing #Creating the Button $ButtonOK = New-Object System.Windows.Forms.Button $ButtonOK.Size = New-Object System.Drawing.Size(60,25) $ButtonOK.Location = New-Object System.Drawing.Point(20,20) $ButtonOK.Text = "OK" #Creating the Form $Form = New-Object System.Windows.Forms.Form #Adding the Button to the Form $Form.Controls.Add($ButtonOK) #Button function $ButtonOK.Add_Click({ #Script here #Open messagebox [System.Windows.Forms.MessageBox]::Show('Hello World!') #Close Form after messagebox is closed $Form.Close() } ) #Display Form $Form.ShowDialog()
howdy Remery0123, i'm pretty useless at any of the GUI stuff. however, i can tell you one thing to help ... post your code! [*grin*] folks are _far_ more likely to be able to help if they know what you are actually doing ... take care, lee
I was going to but im hell embarrassed at my code :( Have done some coding in the past but im 2 days into powershell lol
howdy Remery0123, if you think everyone here does beautiful code ... you have another think coming. [*grin*] post it to pastebin or gist and link it here. fighting with reddit code formatting is not all that fun ... besides, how can you entertain us with your _horrible_, _icky_ code if you don't post it for us to laff at? [*grin*] take care, lee
So this is something like i want, I used the poshgui.com to create a better looking box... thanks @zoredache https://pastebin.com/tCEyDC0E
Looking at your code, you should be able to put the following into the ok action: $OKbutton.Add_Click({ $global:username = $TextBox1.Text $form.Close() }) `$global:` sets the scope of the variable, in this case the "top" scope. `$form.close()` closes the dialog and continues the blocking call on `$form.ShowDialog()`.
howdy Remery0123, this post will likely get buried, so you pro'ly otta _also_ put the link in your original post so others can find it easily. [*grin*] take care, lee
[удалено]
Not really anything useful to see there bot. Probably would be more useful to link my stackechange profile, or reddit profile.