popscreen to fill in data

This topic contains 9 replies, has 6 voices, and was last updated by Profile photo of Jeremy-Smit Jeremy-Smit 1 month, 1 week ago.

  • Author
    Posts
  • #55862
    Profile photo of Jeremy-Smit
    Jeremy-Smit
    Participant

    Hi People,

    I want to create a script that when i run it, there is a pop-up where i can fill in the data that is needed lik.
    activate windows server

    $slmgr = slmgr -ipk 
    slmgr -upk
    
  • #55865
    Profile photo of Mark Prior
    Mark Prior
    Participant

    not sure if this is what your after

    "Enter Data" would be the question you want to ask not the data held in string, Run it you will see what i mean

    $data = Read-Host "Enter Data "
    
    #$data now contains whatever you wrote#
    $data
    
  • #55936
    Profile photo of Peter Jurgens
    Peter Jurgens
    Participant

    Also want to note that slui.exe is kind of the GUI version of slmgr. It will prompt the user to enter a key and activate for you, no need to build anything around slmgr.

  • #56014
    Profile photo of Dan Potter
    Dan Potter
    Participant
    
    
    function Call-tb_psf {
    
    	[void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    	
    	[System.Windows.Forms.Application]::EnableVisualStyles()
    	$form1 = New-Object 'System.Windows.Forms.Form'
    	$button1 = New-Object 'System.Windows.Forms.Button'
    	$textbox1 = New-Object 'System.Windows.Forms.TextBox'
    	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
    	
    	
    	$button1_Click={
    		
    	 $script:text = $textbox1.text
    	
    	}
    	
    	
    	$Form_StateCorrection_Load=
    	{
    		#Correct the initial state of the form to prevent the .Net maximized form issue
    		$form1.WindowState = $InitialFormWindowState
    	}
    	
    	$Form_Cleanup_FormClosed=
    	{
    		
    		try
    		{
    			$button1.remove_Click($button1_Click)
    			$form1.remove_Load($form1_Load)
    			$form1.remove_Load($Form_StateCorrection_Load)
    			$form1.remove_FormClosed($Form_Cleanup_FormClosed)
    		}
    		catch [Exception]
    		{ }
    	}
    	
    	$form1.SuspendLayout()
    	
    	$form1.Controls.Add($button1)
    	$form1.Controls.Add($textbox1)
    	$form1.AutoScaleDimensions = '6, 13'
    	$form1.AutoScaleMode = 'Font'
    	$form1.ClientSize = '287, 95'
    	$form1.Name = 'form1'
    	$form1.Text = 'Form'
    	$form1.add_Load($form1_Load)
    
    	$button1.DialogResult = 'OK'
    	$button1.Location = '164, 60'
    	$button1.Name = 'button1'
    	$button1.Size = '75, 23'
    	$button1.TabIndex = 1
    	$button1.Text = 'button1'
    	$button1.UseVisualStyleBackColor = $True
    	$button1.add_Click($button1_Click)
    	
    	$textbox1.Location = '36, 29'
    	$textbox1.Name = 'textbox1'
    	$textbox1.Size = '203, 20'
    	$textbox1.TabIndex = 0
    	$form1.ResumeLayout()
    	
    	$InitialFormWindowState = $form1.WindowState
    	
    	$form1.add_Load($Form_StateCorrection_Load)
    	
    	$form1.add_FormClosed($Form_Cleanup_FormClosed)
    	
    	return $form1.ShowDialog()
    
    } 
    
    
    Call-tb_psf | out-null
    
    
    $text
    
    
    
    
    
    
    
  • #56069
    Profile photo of Jeremy-Smit
    Jeremy-Smit
    Participant

    Sorry, mayby it was smart for me to tell you guys what the purpose of the script is.

    I whant to create a script tu delete and put in a new windows key for servers, and desktops

    That can be done i know with just to line that we have to fill in. but i want to create a script that gives me a pop-up screen where i put in the key and it then is be done

  • #56090
    Profile photo of Dan Potter
    Dan Potter
    Participant

    above.

  • #56092
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    Have you tried Mark's suggestion with Read-Host. It's probably the simplest method to get input into a script. Then you would use Start-Process to call cscript.exe slmgr.

  • #56096
    Profile photo of James Sudbury
    James Sudbury
    Participant

    Mark's answer also has the added benefit of being accessible to a PSRemoting session. You could push your config to one or more systems from the convenience of your own desk!

    If you really must have a GUI, take a look at this blog series: https://foxdeploy.com/2015/04/10/part-i-creating-powershell-guis-in-minutes-using-visual-studio-a-new-hope/

  • #56098
    Profile photo of Dan Potter
    Dan Potter
    Participant

    Gui above. There are issues with that building method.

  • #56141
    Profile photo of Jeremy-Smit
    Jeremy-Smit
    Participant

    Marks answers works great

You must be logged in to reply to this topic.