Need Help With PowerShell GUI App Using PowerShell Studio 2014

Welcome Forums General PowerShell Q&A Need Help With PowerShell GUI App Using PowerShell Studio 2014

This topic contains 8 replies, has 4 voices, and was last updated by

 
Participant
3 years, 11 months ago.

  • Author
    Posts
  • #23044

    Participant
    Points: 12
    Rank: Member

    I made the skeleton of the GUI and all looks great and now I just have to get some code in. I have a multiline text box where users can type in multiple computer names and a Run box. I have the output going to a GridView using the Out-GridView cmdlet.

    For testing purposes, I am just running test-connection to see if the output looks ok and it does when I enter one computer, BUT, when I enter multiple computers it sees it as one big computer name and it errors out saying that "Test1ComputerTest2ComputerTest3Computer is offline".

    How do I get PowerShell Studio to see each computer on each line as a separate computer in a multiline text box without it seeing it all as one string?

    Thanks

  • #23045

    Keymaster
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Add a backtick-n (backtick, followed by lowercase letter N, in double quotes) to the end of each line. That's a "newline" character.

  • #23046

    Participant
    Points: 12
    Rank: Member

    Thanks Don, I am aware of that method, but do I add that in the multiline textbook of the GUI?

    That would look a little tacky, if that is the case.

    Is there any other way to do this within the code itself?

    Here is my Run button's code:

    $RunButton_Click = {
    	#TODO: Place custom script here
    	
    	$NewLine = "`r`n"
    	
    	$TestConnection = @(
    	Foreach ($ComputerName in $ComputerNamesTextBox.Text)
    	{
    		If ((Test-Connection -ComputerName $ComputerNamesTextBox.Text -Count 1 -Quiet) -eq $true)
    		{
    			$NewLine
    			
    			$ComputerName = $ComputerName.ToUpper()
    			
    			Write-Output "$ComputerName is online!"
    			
    			$NewLine
    		}
    		
    		Else
    		{
    			$NewLine
    			
    			Write-Warning -Message "$ComputerName is offline!"
    			
    			$NewLine
    		}
    	}
    	)
    	
    	$TestConnection | Out-GridView
  • #23048

    Participant
    Points: 60
    Rank: Member

    You could argue that a GUI based application trying to parse a multiline textbox and convert its content into an array instead of using the relatively standard combination of a single line textbox, add and remove buttons, and a list box is tacky... 😉

    Regards your code, another possible way of doing this would be something like below. Might need a bit of tidying up, but sure you'll get the gist of it.

    
    
    $RunButton_Click = {
        #TODO: Place custom script here
     
        [array] $Computers = $ComputerNamesTextBox.Text -split "`n"
    
        $Results = Foreach ($ComputerName in $Computers)
        {
            $ComputerName = $ComputerName.ToUpper()
    
            If ((Test-Connection -ComputerName $ComputerNamesTextBox.Text -Count 1 -Quiet) -eq $true) 
            {
                $Online = $true
            }
     
            Else
            {
                $Online = $False
            }
    
            $hash = @{
                ComputerName = $ComputerName
                Online       = $Online
            }
    
            New-Object -TypeName PSObject -Property $hash
        }
    
        $Results | Out-GridView
    } 
    
    
    
    
  • #23049

    Participant
    Points: 12
    Rank: Member

    I wasn't trying to come off rude and if I did, then my apologies.

    We can go tit for tat here, but I really want to just get this GUI put together and move on to something else.

    But yes, you could argue that, it just all depends on who has more of a consensus in the argument.

    Anyway, thanks for your help I really appreciate it.

    I will give it a shot and get back.

    Again, thank you both for your help.

  • #23057

    Participant
    Points: 60
    Rank: Member

    No worries.

    You can do that combination I mentioned pretty straightforwardly BTW. The Listbox.Items collection can then be parsed in your for..each script for your Test-Connection scriptblock to execute.

    – Drag two buttons, a textbox, and a listbox item onto your form [on the basis that you've already the normal OK, Cancel buttons in place]
    – Rename the text on the textboxes to Add and Remove
    – Configure your add/remove buttons as the following respectively, replacing $lstComputers with the name of the listbox

    $Add_Click={
    	$lstComputers.Items.Add($textbox1.Text)
    }
    
    $buttonRemove_Click={
    	$lstComputers.Items.Remove($lstComputers.SelectedItem)
    }
    

    NB You can also change the setting for the listbox as to whether you can select more than one item.

  • #23058

    Participant
    Points: 12
    Rank: Member

    Awesome!

    Thanks man

  • #23081

    Participant
    Points: 21
    Rank: Member

    Great job. Sir Ask Alot, you can also get help on the PowerShell Studio forum. If you post there and don't get a quick or helpful answer, be sure to ping me at juneb@sapien.com.

    Thanks!
    June

    June Blender
    Technology Evangelist
    SAPIEN Technologies, Inc.

  • #23116

    Participant
    Points: 12
    Rank: Member

    Thanks June

    I just started asking questions on there as well.

    Are there any training videos that Sapien offers with the purchase of this product by any chance?

    The learning curve is a tad steep, but I really need to get this down.

    I may just end up going Visual Studio and using the PowerShell plugin.

    However, I prefer not to do that since I already purchased this product in December.

    Thanks

The topic ‘Need Help With PowerShell GUI App Using PowerShell Studio 2014’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort