none
display results of the power shell commands RRS feed

  • Question

  • Dear all, first i am new to power shell so forgive any misunderstanding

    i have created the folowing power shell code that creates a  window with  buttons. Each of this buttons run power shell commands that manage microsoft lync server. What i want is to be able to see the ruselt of these lync power shell commnds in a popup window. Could you please help me on this? I mean when i press a buton a popup window with the results.

    # Load the Winforms assembly
    [reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")

    # Create the form
    $form = New-Object Windows.Forms.Form
    $form.Size = New-Object Drawing.Size @(300,200)
    #Set the dialog title
    $form.text = "Central Line"
    #Set the Message title
    # Create Button Remove user1
    $button1 = New-Object Windows.Forms.Button
    $button1.text = "Remove user1"
    $button1.Location = New-Object Drawing.Point 20,9
    $button1.Size = New-Object Drawing.Size @(100,30)
    $button1.add_click({import-module Lync

    $y = Get-CsRgsAgentGroup -Identity service:ApplicationServer:lync02.testdomain.com -Name "Central"

    $y.AgentsByUri.Remove("sip:user1@testdomain.com")

    Set-CsRgsAgentGroup -Instance $y

    })

    $form.controls.add($button1)

    # Create Button Add user1
    $button3 = New-Object Windows.Forms.Button
    $button3.text = "Add user1"
    $button3.Location = New-Object Drawing.Point 175,129
    $button3.Size = New-Object Drawing.Size @(100,30)
    $button3.add_click({import-module Lync

    $y = Get-CsRgsAgentGroup -Identity service:ApplicationServer:lync02.testdomain.com -Name "Central "
     
    $y.AgentsByUri.Add("sip:user1@testdomain.com")

    Set-CsRgsAgentGroup -Instance $y
    })
    $form.controls.add($button3)
    $form.ShowDialog()


    • Edited by pantoskom Wednesday, April 9, 2014 11:50 AM
    Wednesday, April 9, 2014 11:49 AM

Answers

  • [System.Windows.Forms.MessageBox]::Show("My messafe","My Title")

    ¯\_(ツ)_/¯

    • Marked as answer by pantoskom Monday, April 14, 2014 8:06 AM
    Wednesday, April 9, 2014 12:00 PM

All replies

  • [System.Windows.Forms.MessageBox]::Show("My messafe","My Title")

    ¯\_(ツ)_/¯

    • Marked as answer by pantoskom Monday, April 14, 2014 8:06 AM
    Wednesday, April 9, 2014 12:00 PM
  • Hi,

    What you mean? I don't want to just popup a message. I need to popup if the PowerShell command run succsefuly or has error

    Wednesday, April 9, 2014 3:21 PM
  • Hi,

    What you mean? I don't want to just popup a message. I need to popup if the PowerShell command run succsefuly or has error

    You asked for a popup. There is the popup.  You need to place it where you need it in your code.  I think you can handle an "IF" statement can't you?

    if(there is an error){ popup message }

    I have no idea what your script is trying to do so you need to figure this out and place the code where it is needed.


    ¯\_(ツ)_/¯

    Wednesday, April 9, 2014 4:14 PM
  • [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
    # Load the Winforms assembly
    Add-Type -AssemblyName System.Windows.Forms
    # Create the form
    $form = New-Object Windows.Forms.Form
    $form.Size = New-Object Drawing.Size @(300,250)
    $Image = [system.drawing.image]::FromFile("C:\remoteapp\test.png")
    $Form.BackgroundImage = $Image
    $Form.BackgroundImageLayout = "None"
    #Set the dialog title
    $form.text = "testdomain Central Line"
    # Create Button Remove user1 from lync group
    $button1 = New-Object Windows.Forms.Button
    $button1.text = "Remove user1"
    $button1.Location = New-Object Drawing.Point 20,9
    $button1.Size = New-Object Drawing.Size @(100,30)
    $button1.add_click({[System.Windows.Forms.MessageBox]::Show("user1 was removed from testdomain central Line. Please Check by presing SHOW CENTRAL LINE.If not removed please try again in 1 minute1")})
    $button1.add_click({import-module Lync
    
    $y = Get-CsRgsAgentGroup -Identity service:ApplicationServer:lync02.testdomain.com -Name "Central Offices"
    
    $y.AgentsByUri.Remove("sip:user1@testdomain.com")
    
    Set-CsRgsAgentGroup -Instance $y
    })
    $form.controls.add($button1)
    # Create Button Add user1 to lync groups
    $button7 = New-Object Windows.Forms.Button
    $button7.text = "Add user1"
    $button7.Location = New-Object Drawing.Point 175,9
    $button7.Size = New-Object Drawing.Size @(100,30)
    $button7.add_click({[System.Windows.Forms.MessageBox]::Show("user1 was added to testdomain central Line. Please Check by presing SHOW CENTRAL LINE.If not added please try again in 1 minute")})
    $button7.add_click({import-module Lync
    
    $y = Get-CsRgsAgentGroup -Identity service:ApplicationServer:lync02.testdomain.com -Name "Central Offices"
     
    $y.AgentsByUri.Add("sip:user1@testdomain.com"")
    
    Set-CsRgsAgentGroup -Instance $y
    })
    $form.controls.add($button7)
    # Create Button Show Central Line
    $button12 = New-Object Windows.Forms.Button
    $button12.text = "Show Central Line"
    $button12.Location = New-Object Drawing.Point 20,160
    $button12.Size = New-Object Drawing.Size @(255,40)
    $button12.add_click({$process = New-Object System.Diagnostics.Process;
    [Diagnostics.Process]::Start("powershell.exe","C:\remoteapp\CL4.ps1")
    })
    $form.controls.add($button12)
    $form.ShowDialog()

    Hi jrv, thank you for your advices. What I was trying to achieve was our 5 receptionists to add and remove them self from lync response group. I have finally completed my job by adding one more button. I have added the "show central line" button that shows who is currently agent on central line, so they know each time they add or remove someone  if it was added or not. Below you can find the code in case someone needs to do the same. thank you.

     

     

    Monday, April 14, 2014 8:05 AM