Quantcast
Viewing all articles
Browse latest Browse all 2314

Fehlerhaftes Auslesen einer Variable

Hallo zusammen,

und zwar verzweifel ich seit einigen Tagen an einem Script für das auslesen einer OU aus der AD.

Hier einmal mein Script:

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

$objForm = New-Object System.Windows.Forms.Form
$objForm.ClientSize = New-Object System.Drawing.Size(407, 390)
$objForm.topmost = $true

# OU Auswahl 

$objText1 = New-Object System.Windows.Forms.Label
$objText1.Location = New-Object System.Drawing.Size(10,10) 
$objText1.Size = New-Object System.Drawing.Size(280,20) 
$objText1.Text = "Bitte OU auswählen: "
$objForm.Controls.Add($objText1) 

$computerNames = @(Get-ADOrganizationalUnit -Property Name  -Filter {(Name -like "NLTer*") -or (Name -like "TSI*") -or (Name -like "ZL1*") -or (Name -like "HAMM*")}  -SearchBase 'OU=Land,DC=ads,DC=Firma,DC=net' | select -Expandproperty Name)
$comboBox1 = New-Object System.Windows.Forms.Combobox
$comboBox1.Location = New-Object System.Drawing.Size(10, 30)
$comboBox1.Size = New-Object System.Drawing.Size(300, 20)
$comboBox1.sorted = $true;
foreach($computer in $computerNames)
{
  $comboBox1.Items.add($computer)
}

$objForm.Controls.Add($comboBox1)

# OU Auswahl ende


# Buttons für OU Auswahl 1

$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Point(110, 50)
$Button.Size = New-Object System.Drawing.Size(75, 23)
$Button.Text = "Weiter"
$Button.add_Click({ListBox})
$objForm.Controls.Add($Button)

$Button2 = New-Object System.Windows.Forms.Button
$Button2.Location = New-Object System.Drawing.Point(191, 50)
$Button2.Size = New-Object System.Drawing.Size(120, 23)
$Button2.Text = "Eingabe Speichern"
$Button2.add_Click({$objText4.Text = $comboBox1.SelectedItem.ToString()})
$objForm.Controls.Add($Button2)


# --------------------------------------------------------------------------



# Abteilungs Auswahl 

$objText2 = New-Object System.Windows.Forms.Label
$objText2.Location = New-Object System.Drawing.Size(10,100) 
$objText2.Size = New-Object System.Drawing.Size(280,20) 
$objText2.Text = "Wählen Sie die NL oder Abteilung aus:"
$objForm.Controls.Add($objText2) 


Function ListBox
{

$searchou = "OU=" + $objText4.Text + ",OU=Land,DC=ads,DC=Firma,DC=net"

$computerNames2 = @(Get-ADOrganizationalUnit -Property Name  -Filter {(Name -like "*")} -SearchBase $searchou | select -Expandproperty Name)
$ListBoxOU = New-Object System.Windows.Forms.Combobox 
$ListBoxOU.Location = New-Object System.Drawing.Size(10,120) 
$ListBoxOU.Size = New-Object System.Drawing.Size(300,20) 
$ListBoxOU.sorted = $true;

foreach($computers2 in $computerNames2) 
{
  $ListBoxOU.Items.add($computers2)
}

$objForm.Controls.Add($ListBoxOU)

}

# Buttons für NL Auswahl 2

$Button3 = New-Object System.Windows.Forms.Button
$Button3.Location = New-Object System.Drawing.Point(191, 140)
$Button3.Size = New-Object System.Drawing.Size(120, 23)
$Button3.Text = "Eingabe Speichern"
$Button3.add_Click({$objText5.text = $ListBoxOU.SelectedItem.ToString()})
$objForm.Controls.Add($Button3)

# Button ende


$objText4 = New-Object System.Windows.Forms.Label
$objText4.Location = New-Object System.Drawing.Size(20,300) 
$objText4.Size = New-Object System.Drawing.Size(200,20) 
$objText4.Text = "1"
$objForm.Controls.Add($objText4) 


$objText5 = New-Object System.Windows.Forms.Label
$objText5.Location = New-Object System.Drawing.Point(20, 320)
$objText5.Size = New-Object System.Drawing.Size(200, 20)
$objText5.Text = "2"
$objForm.Controls.Add($objText5)


[void]$objForm.showdialog()

Komischerweise ließt er die erste Variable aus nur die zweite nicht.

Ich hoffe mir kann jemand einen Tipp geben.

Liebe Grüße 

Nils


Viewing all articles
Browse latest Browse all 2314


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>