Willkommen bei SCHROETER|EDV

Startseite > Dokumentation > Microsoft > CMD/PowerShell > PowerShell - PS Gui für Ping erstellen

PowerShell - PS Gui für Ping erstellen


Beschreibung

Windows PowerShell kann anhand von vorhandenen Bibliotheken Anwendunges- Oberflächen (Gui - Graphic User Interface) erstellen.

Dieses Beispiel zeigt wie man ein Fenster erstellt, indem ein Ping abgesetzt werden kann und das Ergebnis im Anzeigefenster heraus kopieren kann.

 

[Author]

Auf der Suche nach einem Tool um ein Windows 2008 R2 Core Server zu verwalten, bin ich auf die Seite mit den Tool Beispiel gestoßen. Laut MS Press und Galileo Books ist die Administrations- Oberfläche ab Win 2008 (die Management Fenster) auf Basis von PowerShell erstellt worden.

[Author]

 

Code (Copy&Paste)

##############################################

# © Andrei Ursuleac

# Link: http://sysadminemporium.wordpress.com/2012/11/26/powershell-gui-front-end-for-your-scripts-episode-1/

# additional: other Window Icon

##############################################

  

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

$Form = New-Object System.Windows.Forms.Form

$Form.Size = New-Object System.Drawing.Size(640,480)

  

############################################## Start Icon

$Icon = [system.drawing.icon]::ExtractAssociatedIcon($PSHOME + "\powershell.exe")

$Form.Icon = $Icon

############################################## end Icon

 

############################################## Start functions

function pingInfo {

$wks=$InputBox.text;

$pingResult=ping $wks | fl | out-string;

$outputBox.text=$pingResult

                     } #end pingInfo

############################################## end functions

 

############################################## Start text fields

$InputBox = New-Object System.Windows.Forms.TextBox

$InputBox.Location = New-Object System.Drawing.Size(20,50)

$InputBox.Size = New-Object System.Drawing.Size(150,40)

$Form.Controls.Add($InputBox)

 

$outputBox = New-Object System.Windows.Forms.TextBox

$outputBox.Location = New-Object System.Drawing.Size(10,150)

$outputBox.Size = New-Object System.Drawing.Size(600,260)

$outputBox.MultiLine = $True

$outputBox.ScrollBars = "Vertical"

$Form.Controls.Add($outputBox)

############################################## end text fields

 

############################################## Start buttons

$Button = New-Object System.Windows.Forms.Button

$Button.Location = New-Object System.Drawing.Size(400,30)

$Button.Size = New-Object System.Drawing.Size(110,80)

$Button.Text = "Ping"

$Button.Add_Click({pingInfo})

$Form.Controls.Add($Button)

############################################## end buttons

  

$Form.Add_Shown({$Form.Activate()})

[void] $Form.ShowDialog()

 

PowerShell - Ping mit GUI
Bild zum vergrößern anklicken ...

 


Quelle: http://sysadminemporium.wordpress.com/category/powershell/

Inhaltsverzeichnis:

732.109 Besucher
885.394 Seitenaufrufe
1,21 Seitenaufrufe/Besucher

Powered by CMSimple | Template: ge-webdesign.de | Login

nach oben