
135531
22.02.2018
PowerShell GUI, Cmdlet in ComboBox ausführen
Hi @all,
ich bin absoluter Neuling wenn es um die nutzung von PowerShell geht. Dennoch versuche ich im Moment eine PowerShell GUI zu bauen um das Discrete Device Assignment (DDA) zu vereinfachen.
Mein Problem ist, dass ich keine Ahnung habe wie ich ein Befehl (Cmdlet) in einer ComboBox ausführe, sprich --> klick auf ComboBox Ausgabe des Befehls erscheint zur Auswahl.
Genauer gesagt will ich es so haben, dass ich in der ComboBox alle VMs des Lokalen Servers (PCs) zur Auswahl habe.
Also soll der Befehl Get-VM ausgeführt werden und die Ausgabe in der ComboBox zur Auswahl stehen.
Aber wie funktioniert das ? :/ Kann mir da jemand helfen ?
Mein PowerShell skript sieht aktuell wie folgt aus :
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form
$objForm.Backcolor="White"
$objForm.BackgroundImageLayout = 2
$objForm.BackgroundImage =[System.Drawing.Image]::FromFile('C:\Users\jannikr\Pictures\Microsoft-Logo.jpg')
$objForm.StartPosition = "CenterScreen"
$objForm.Size = New-Object System.Drawing.Size(650,650)
$objForm.Text = "Discrete Device Assignment"
#VM Namen eingeben
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(50,50)
$objLabel.Size = New-Object System.Drawing.Size(250,50)
$objLabel.Text = "Bitte wählen sie eine VM aus:"
$objForm.Controls.Add($objLabel)
$objComboBox = New-Object System.Windows.Forms.Combobox
$objComboBox.Location = New-Object System.Drawing.Size(50,100)
$objComboBox.Size = New-Object System.Drawing.Size(250,50)
[void] $objComboBox.Items.Add("VM-Name")
$objComboBox.Height = 70
$objForm.Controls.Add($objComboBox)
$objForm.TopMost = $True
$objComboBox.Add_SelectedIndexChanged({ })
function Get-VM ()
{
if ($objComboBox.SelectedItem -eq "VM-Name")
Get-VM
}
Wie Ihr sehen könnt habe ich nichtmal einen Ansatzpunkt um mein Vorhaben in die Realität umzusetzen...
Ich nehme jedes Ratschlag/Tipp an den ich bekommen kann!!! :D
ich bin absoluter Neuling wenn es um die nutzung von PowerShell geht. Dennoch versuche ich im Moment eine PowerShell GUI zu bauen um das Discrete Device Assignment (DDA) zu vereinfachen.
Mein Problem ist, dass ich keine Ahnung habe wie ich ein Befehl (Cmdlet) in einer ComboBox ausführe, sprich --> klick auf ComboBox Ausgabe des Befehls erscheint zur Auswahl.
Genauer gesagt will ich es so haben, dass ich in der ComboBox alle VMs des Lokalen Servers (PCs) zur Auswahl habe.
Also soll der Befehl Get-VM ausgeführt werden und die Ausgabe in der ComboBox zur Auswahl stehen.
Aber wie funktioniert das ? :/ Kann mir da jemand helfen ?
Mein PowerShell skript sieht aktuell wie folgt aus :
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form
$objForm.Backcolor="White"
$objForm.BackgroundImageLayout = 2
$objForm.BackgroundImage =[System.Drawing.Image]::FromFile('C:\Users\jannikr\Pictures\Microsoft-Logo.jpg')
$objForm.StartPosition = "CenterScreen"
$objForm.Size = New-Object System.Drawing.Size(650,650)
$objForm.Text = "Discrete Device Assignment"
#VM Namen eingeben
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(50,50)
$objLabel.Size = New-Object System.Drawing.Size(250,50)
$objLabel.Text = "Bitte wählen sie eine VM aus:"
$objForm.Controls.Add($objLabel)
$objComboBox = New-Object System.Windows.Forms.Combobox
$objComboBox.Location = New-Object System.Drawing.Size(50,100)
$objComboBox.Size = New-Object System.Drawing.Size(250,50)
[void] $objComboBox.Items.Add("VM-Name")
$objComboBox.Height = 70
$objForm.Controls.Add($objComboBox)
$objForm.TopMost = $True
$objComboBox.Add_SelectedIndexChanged({ })
function Get-VM ()
{
if ($objComboBox.SelectedItem -eq "VM-Name")
Get-VM
}
Wie Ihr sehen könnt habe ich nichtmal einen Ansatzpunkt um mein Vorhaben in die Realität umzusetzen...
Ich nehme jedes Ratschlag/Tipp an den ich bekommen kann!!! :D
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 365754
Url: https://administrator.de/forum/powershell-gui-cmdlet-in-combobox-ausfuehren-365754.html
Ausgedruckt am: 01.05.2025 um 03:05 Uhr
6 Kommentare
Neuester Kommentar

$objComboBox.Add_SelectedIndexChanged({
[System.Windows.Forms.MessageBox]::Show((Get-VM -Name $objComboBox.SelectedItem | fl * | out-string))
})

s.o. Hatte die MessageBox vergessen °|°
Die Combobox musst du ja vorher erst mal füllen ...Z.B. im Load-Event der Form.
Die Combobox musst du ja vorher erst mal füllen ...Z.B. im Load-Event der Form.
$objForm.add_Load({
$objComboBox.Items.AddRange((get-vm | select -Expand Name))
})

Zitat von @135531:
Aber wie fülle ich die ComboBox ? Bzw. was ist das Load-Event der Form ?
Steht im letzten Post.Aber wie fülle ich die ComboBox ? Bzw. was ist das Load-Event der Form ?