AdUser Manager Version 1.2

Hier kann der ADUser Manager heruntergeladen werden

der Manager hilft dabei AD-Benutzer anzulegen, zu bearbeiten und zu kopieren! Es können viele relevante Benutzerbezogene Daten verändert werden. Zudem sind auch TS-Profil Informationen konfigurierbar. Beim Kopieren von AD-Benutzern, können Gruppenmitgliedschaften ebenfalls kopiert werden!

<#
	.SYNOPSIS
		Usermanagement Tool Version 1.2 by Andres Sichel
	
	.DESCRIPTION
		Dieses Programm ermöglicht das schnelle und einfache bearbeiten von AD-Benutzern. Es beherrscht das bearbeiten 
		und ändern aller Eigenschaften auf einer Seite in einem Fenster. Zudem können auch Benutzer kopiert werden mit einer manuellen Auswahl an
		den Gruppen die der neue Benutzer erhalten soll. Bei dem Kopiervorgang, oder auch der Neuanlage kann zudem auch ein Postfach erstellt werden. 
	
	.EXAMPLE
				PS C:\> UsermanagementTool_V1.2.ps1 / UsermanagementTool_V1.2.exe
	
	.NOTES
		Die Settings.ini definiert: 
			- den zu verwenden Domänencontroller
			- die "Start-OU" anhand auch die Benutzerliste geladen wird
			- ob die Exchange-Server CMDLets geladen werden sollen /wenn Ja geschieht die Authentifizierung mit aktuellem Benutzer & Kennwort
			- den zu verwendende Exchange-Server (muss festgelegt werden)
			- den Namen des Erweiterten Attributs 15 (0 = inaktiv / 1 = aktiv)
		Sind die Exchange-CMDLets nicht geladen können auch keine Benutzerdefinierten Attribute gesetzt / geändert werden. 
#>

# Ausführungspfad wichtig für die Settings.ini und das Icon
$scriptRoot = [System.AppDomain]::CurrentDomain.BaseDirectory.TrimEnd('\')
if ($scriptRoot -eq $PSHOME.TrimEnd('\'))
{
    $scriptRoot = $PSScriptRoot
}

# Systembibliotheken laden
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.VisualStyles")
[void][reflection.assembly]::Load("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
[void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
[void][reflection.assembly]::Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

#########################################################################################################################################
#INIfile laden
function Get-IniContent ($scriptRoot)
{
    $ini = @{}
    switch -regex -file $scriptRoot
    {
        "^\[(.+)\]" # Section
        {
            $section = $matches[1]
            $ini[$section] = @{}
            $CommentCount = 0
        }
        "^(;.*)$" # Comment
        {
            $value = $matches[1]
            $CommentCount = $CommentCount + 1
            $name = "Comment" + $CommentCount
            $ini[$section][$name] = $value
        } 
        "(.+?)\s*=(.*)" # Key
        {
            $name,$value = $matches[1..2]
            $ini[$section][$name] = $value
        }
    }
    return $ini
}

$globalsettingsfile = "$scriptRoot\settings.ini"
$inifile = get-inicontent "$globalsettingsfile"

#########################################################################################################################################
#Werte aus der Settings.INI einlesen und Globale Variabeln

$Version = "1.2"

#Welcher DC soll verwendet werden?
$ADDCServer = $inifile.UserManager.ADDC

#Welche OU soll für Abfragen verwendet werden?
$OUSearch = $inifile.UserManager.OU

#Soll Exchange geladen werden? 
$LoadExchangeCMDLets = $inifile.UserManager.LoadEXCMDlets

#Exchange Server Name
$Server = $inifile.UserManager.ExchangeServerName

#Extension Attribut 15 - namen definieren
$AdExt15 = $inifile.UserManager.AdExt15

#Welche Domäne und DNSRoot haben wir?
$ADNetBIOSName = (get-addomain).NetBIOSName
$ADDNSRoot = (get-addomain).DNSRoot

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

# Hauptfensterfenster erstellen und Variablen für Breite & Höhe angeben

$WindowWidth = 1130
$WindowHeight = 790

$Icon = [system.drawing.icon]::ExtractAssociatedIcon("$scriptRoot\icon1.ico")
$Font = New-Object System.Drawing.Font("Arial",10,[System.Drawing.FontStyle]::Regular)
$Fenster1 = New-Object System.Windows.Forms.Form
$Fenster1.Size = New-Object System.Drawing.Size($WindowWidth,$WindowHeight)
$Fenster1.MaximumSize = "$WindowWidth,$WindowHeight"
$Fenster1.MinimumSize = "$WindowWidth,$WindowHeight"
$Fenster1.Text = "Usermanagement Tool $Version "
$Fenster1.StartPosition = "CenterScreen"
$Fenster1.BackColor = "#B2E4FF"
$Fenster1.Icon = $Icon
$Fenster1.Font = $Font
$Fenster1.WindowState = "Normal"
$Fenster1.add_SizeChanged({Minimieren})

#Tabs erstellen
$TabUserEdit = New-Object 'System.Windows.Forms.TabPage'
$TabUserCreate = New-Object 'System.Windows.Forms.TabPage'
$Fortschritt = New-Object System.Windows.Forms.ProgressBar


#Kontextmenü für Icon erstellen
$Kontext = New-Object System.Windows.Forms.ContextMenu
$KontextExit = New-Object System.Windows.Forms.MenuItem
$KontextInfo = New-Object System.Windows.Forms.MenuItem

$KontextExit.Text = "Exit"
$KontextExit.Index = 1
$KontextExit.add_Click({$NotifyIcon.Visible = $False,$Fenster1.close()})

$KontextInfo.Text = "Info"
$KontextInfo.Index = 2
$KontextInfo.add_Click({ShowInfo})

# NotifyIcon erstellen, erscheint wenn Fenster minimiert worden ist
$NotifyIcon = New-Object System.Windows.Forms.NotifyIcon
$NotifyIcon.Icon = $Icon
$NotifyIcon.Visible = $false
$NotifyIcon.add_Click({Iconclick})
$NotifyIcon.Text = "Usermanagement Tool"
$NotifyIcon.BalloonTipTitle = "Usermanagement Tool"
$NotifyIcon.BalloonTipText = "Usermanagement Tool wurde minnimiert, Klick zum öffnen"
$NotifyIcon.BalloonTipIcon = "Info"
$NotifyIcon.ContextMenu = $Kontext
$NotifyIcon.ContextMenu.MenuItems.AddRange($KontextInfo)
$NotifyIcon.ContextMenu.MenuItems.AddRange($KontextExit)

function ShowInfo
{
$Fenster1.Hide()
$Fenster2 = New-Object System.Windows.Forms.Form
$Fenster2.Size = New-Object System.Drawing.Size(300,300)
$Fenster2.MaximumSize = "300,300"
$Fenster2.MinimumSize = "300,300"
$Fenster2.Text = "Usermanagement Tool Info"
$Fenster2.StartPosition = "CenterScreen"
$Fenster2.BackColor = "#B2E4FF"
$Fenster2.Icon = $Icon
$Fenster2.Font = $Font
$Fenster2.WindowState = "Normal"


#Text1
$Text3 = New-Object System.Windows.Forms.Label
$Text3.Location = New-Object System.Drawing.Size(20,20)
$Text3.Size = New-Object System.Drawing.Size(240,150)
$Text3.Text = "Usermanagement Tool

Erstellt von Andres Sichel

blog@asichel.de

Version $Version"
#$Text3.BackColor = "red"
$Text3.TextAlign = "MiddleCenter"
$Fenster2.Controls.Add($Text3)

$FontB = New-Object System.Drawing.Font("Arial",14,[System.Drawing.FontStyle]::Regular)
$CloseInfo = New-Object System.Windows.Forms.Button
$CloseInfo.Location = New-Object System.Drawing.Size(90,200)
$CloseInfo.Size = New-Object System.Drawing.Size(100,30)
$CloseInfo.Text = "OK"
$CloseInfo.BackColor = "#0064AF"
$CloseInfo.font = $FontB
$CloseInfo.foreColor = "White"
$CloseInfo.Add_Click({$Fenster2.Close()})
$Fenster2.Controls.Add($CloseInfo)

$Bild1 = New-Object System.Windows.Forms.PictureBox
$Bild1.Location = New-Object System.Drawing.Size(3,0)
$Bild1.ImageLocation = "$scriptRoot\Bild.png"
$Bild1.SizeMode = "AutoSize"
$Fenster2.Controls.Add($Bild1)

$Fenster2.Add_Shown({$Fenster2.Activate()})
[void] $Fenster2.ShowDialog()
}

function Minimieren
{
    if($Fenster1.WindowState -eq [Windows.Forms.FormWindowState]"Minimized")
    {
      $Fenster1.Hide()
      $NotifyIcon.Visible = $True      
      $NotifyIcon.ShowBalloonTip(5000)
    }       

}

function IconClick
{
    if($Fenster1.Visible)
    {
        $Fenster1.Hide()
    }
    else
    {        
        $Fenster1.Show()        
        $Fenster1.WindowState = [Windows.Forms.FormWindowState]"Normal"
    }
}

# Enter drücken zulassen (nur für Benutzerabfragen)
$Fenster1.KeyPreview = $True
$Fenster1.Add_KeyDown({if ($_.KeyCode -eq "Enter"){Abfrage;BearbeitungDeaktivieren;FelderReset}})
# Mit Escape wird Abmelden ausgeführt und das Fenster wird geschlossen
$Fenster1.Add_KeyDown({if ($_.KeyCode -eq "Escape"){ Abmelden }})

#Handler erstellen für Checkboxen
$handlerPWDChange = {
                    if ($PWDChange.Checked -eq $true)
                    {
                    $txtBoxPWDChange.ReadOnly = $false
                    $PWDChangeNextLogon.Enabled = $true
                    }
                    else
                    {
                    $txtBoxPWDChange.ReadOnly = $true
                    $PWDChangeNextLogon.Enabled = $false
                    $PWDChangeNextLogon.Checked = $false
                    $txtBoxPWDChange.Text = ""
                    }
                    }

$handlerPWDOptions = {
                     
                     if ($PWDablauf.Checked -eq $true)
                     {
                     $PWDmustChange.Checked = $false
                     $PWDmustChange.Enabled = $false
                     }
                     else
                     {
                     if ($PWDcantChange.Checked -eq $true)
                        {$PWDmustChange.Enabled = $false}
                        else
                        {$PWDmustChange.Enabled = $true}
                     }

                     if ($PWDmustChange.Checked -eq $true)
                     {
                     $PWDablauf.Checked = $false
                     $PWDablauf.Enabled = $false
                     $PWDcantChange.Checked = $false
                     $PWDcantChange.Enabled = $false
                     }
                     else
                     {
                     $PWDablauf.Enabled = $true
                     $PWDcantChange.Enabled = $true      
                     }
                   
                     } 
                          
$handlerPWDOptions1 = {
                      if ($PWDcantChange.Checked -eq $true)
                     {
                     $PWDmustChange.Enabled = $false
                     $PWDmustChange.Checked = $false
                     }
                     else
                     {
                     if ($PWDablauf.Checked -eq $true)
                        {$PWDmustChange.Enabled = $false}
                        else
                        {$PWDmustChange.Enabled = $true}
                     }
                     }
                     
$ExchangeHandler = {
                    if ($CHKBoxExchangeMailbox.Checked -eq $true)
                     {
                     $Fenster1.Cursor = [System.Windows.Forms.Cursors]::WaitCursor       
                     #Am Exchange Server anmelden
                     #Zertifikatsprüfungen abschalten
                     $SkipCertificate = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck -Verbose

                     #Servernamen auslesen
                     
                              
                        #Anmeldedaten erfragen
                        #$cred = Get-Credential

                        #PS-Session starten --> Bei connection URI den korrekten Exchange 2010 oder 2013 Servernamen eingeben, vorzugsweise CAS-Server
                        $Session = New-PSSession `
                                         -ConfigurationName Microsoft.Exchange `
                                         -ConnectionUri http://$Server/PowerShell/ `
                                         -Authentication Kerberos `
                                         -SessionOption $SkipCertificate  `
                                         -Name Exchange
                                  

                        #Importieren der erzeugten Session in die aktuelle Session, lokal gleichlautende Befehle werden ersetzen
                        Import-PSSession -Session $Session -AllowClobber -Verbose
                        $Fenster1.Cursor = [System.Windows.Forms.Cursors]::Arrow
  
                      $SpeichernCreate.Text = "Benutzer mit Postfach anlegen"
                      $ADExtensioAttributes.Enabled = $true
                      $txtBoxAdExt1Create.Enabled = $true
                      $txtBoxAdExt2Create.Enabled = $true
                      $DatabaseAutoSelect.Enabled = $true
                      $DatabaseAutoSelect.Checked = $true                                          
                      $DatabaseManualSelect.Enabled = $true
                      $CHKBoxrolePolicy.Enabled = $true
                      $CHKBoxEASPolicy.Enabled = $true
                      $CHKBoxABPolicy.Enabled = $true
                      
                     }
                     else 
                     {
                      Remove-PSSession -Name Exchange                      
                      $DatabaseAutoSelect.Enabled = $false
                      $DatabaseManualSelect.Enabled = $false
                      $DatabaseName.Enabled = $false
                      $DatabaseAutoSelect.Checked = $false
                      $DatabaseManualSelect.Checked = $false
                      $CHKBoxrolePolicy.Checked = $false
                      $CHKBoxrolePolicy.Enabled = $False
                      $CHKBoxEASPolicy.Checked = $false
                      $CHKBoxEASPolicy.Enabled = $false
                      $CHKBoxABPolicy.Checked = $false
                      $CHKBoxABPolicy.Enabled = $false
                      $txtBoxAdExt1Create.Enabled = $false
                      $txtBoxAdExt2Create.Enabled = $false
                      $SpeichernCreate.Text = "Benutzer anlegen"  

                    }           
                   }    

$RolePolicyHandler = {
                      $RolePolicy.Enabled = $true
                      $RolePolicys = Get-RoleAssignmentPolicy | sort-object
                      $RolePolicy.Items.Clear()
                      foreach($Role in $RolePolicys){$RolePolicy.items.add($RolePolicys.Name)}
                      if ($CHKBoxrolePolicy.Checked -eq $false) {$RolePolicy.ResetText(),$RolePolicy.Enabled = $false} 
                     }
$EASPolicyHandler = {
                     $EASPolicy.Enabled = $true
                     $EAS = Get-ActiveSyncMailboxPolicy | sort-object
                     $EASPolicy.Items.Clear()
                     foreach($EASPol in $EAS){$EASPolicy.items.add($EAS.Name)}
                     if ($CHKBoxEASPolicy.Checked -eq $false) {$EASPolicy.ResetText(),$EASPolicy.Enabled = $false}
                    }
$ABPolicyHandler = {
                     $ABPolicy.Enabled = $true
                     $ABooks = Get-AddressBookPolicy | sort-object
                     $ABPolicy.Items.Clear()
                     foreach($ABPol in $ABooks){$ABPolicy.items.add($ABooks.Name)}
                     if ($CHKBoxABPolicy.Checked -eq $false) {$ABPolicy.ResetText(),$ABPolicy.Enabled = $false}
                   }     
                   
$DabaseSelectHandler = {
                      if ($DatabaseAutoSelect.Checked -eq $true)
                        {
                         $DatabaseName.Enabled = $false
                         $DatabaseName.ResetText()
                        }
                      if ($DatabaseManualSelect.Checked -eq $true)
                        {
                        $DatabaseArray = Get-MailboxDatabase | sort-object
                        $DatabaseName.Items.Clear()
                        foreach($DB in $DatabaseArray){$DatabaseName.items.add($DB.Name)}
                        $DatabaseName.Enabled = $true
                        }      
            
                                                            
                      }  
#Funktionen erstellen
function Abfrage
{
    
    $Fortschritt.Visible = $false
    $FortschrittText.Text = ""

    $membership.Items.Clear();
    
    $ADUser = 0;
    $ADUserDaten = 0;
    $ADUser = $UserName.Text


     if (($Username.text.Length -eq 0) -or (!(dsquery user -samid $ADUser)))

        {
        $KeinBenutzer = [Windows.Forms.MessageBox]
        $KeinBenutzer::Show("Benutzer nicht gefunden. Bitte NT-Benutzernamen angeben" , "Benutzer nicht gefunden", "OK", "Error") 
        return 0;
        exit;
        }
       
    if ($LoadExchangeCMDLets -eq "Ja")
    {
    $ADUserDaten = Get-Aduser -Server "$ADDCServer" -Identity "$ADUser" -Properties employeeID, employeeNumber,Surname, GivenName, SamAccountName, Mail, mailNickname, 
                                   Description, Office, telephoneNumber, mobile, facsimileTelephoneNumber, title, department, Company,
                                   scriptPath, homeDrive, homeDirectory,extensionAttribute1, extensionAttribute2, extensionAttribute15
    } 
    else
    {
    $ADUserDaten = Get-Aduser -Server "$ADDCServer" -Identity "$ADUser" -Properties employeeID, employeeNumber,Surname, GivenName, SamAccountName, Mail, 
                                   Description, Office, telephoneNumber, mobile, facsimileTelephoneNumber, title, department, Company,
                                   scriptPath, homeDrive, homeDirectory
    }
                                                                           
    if ($ADUserDaten.Enabled -eq "True"){$StatusBox.Checked = $true}else{$StatusBox.Checked = $false}
    
    if ($ADUserDaten.extensionAttribute15 -eq "1"){ $CHKBoxADExt15.Checked = $true }else{ $CHKBoxADExt15.Checked = $false }    
    
    $ADUserDN = $ADUserDaten.DistinguishedName
    $TSAD = [ADSI] "LDAP://$ADUSerDN"

    $DN = $ADUserDaten.DistinguishedName
    $PATH = $DN.substring($dn.IndexOf("OU=")).split(".")
    
    $ADOUTxt.Text = "$PATH"   
    
    $txtBoxEmployeeID.text = $ADUserDaten.EmployeeID
    $txtBoxNachname.text = $ADUserDaten.Surname
    $txtBoxVorname.text = $ADUserDaten.GivenName
    $txtBoxSam.text = $ADUserDaten.SamAccountName
    $txtBoxMail.text = $ADUserDaten.Mail
    $txtBoxAlias.text = $ADUserDaten.mailNickname
    $txtBoxBeschreibung.text = $ADUserDaten.Description
    $txtBoxOffice.text = $ADUserDaten.Office
    $txtBoxPhone.text = $ADUserDaten.telephoneNumber
    $txtBoxMobil.text = $ADUserDaten.Mobile
    $txtBoxFax.text = $ADUserDaten.facsimileTelephoneNumber
    $txtBoxPosition.text = $ADUserDaten.Title
    $txtBoxAbteilung.text = $ADUserDaten.Department
    $txtBoxFirma.text = $ADUserDaten.Company
    $txtBoxEmployeeNr.text = $ADUserDaten.EmployeeNumber
    $txtBoxADSkript.text = $ADUserDaten.ScriptPath
    $txtBoxADDriveLetter.text = $ADUserDaten.HomeDrive
    $txtBoxADPath.text = $ADUserDaten.HomeDirectory
    $txtBoxAdExt1.text = $ADUserDaten.extensionAttribute1
    $txtBoxAdExt2.text = $ADUserDaten.extensionAttribute2

    $GroupBoxUserData1.Text = "Stammdaten von Benutzer: "  +$ADUserDaten.Name+  ""
    $GroupBoxUserData2.Text= "Organisationsdaten von Benutzer: "  +$ADUserDaten.Name+  ""
    $GroupBoxUserData3.Text= "AD-Profil von Benutzer: "  +$ADUserDaten.Name+  ""
    $GroupBoxUserData4.Text= "Terminalservice von Benutzer: "  +$ADUserDaten.Name+  ""
    $GroupBoxUserOU.Text = "OU / Benutzerstatus von Benutzer: "  +$ADUserDaten.Name+  ""
    $GroupBoxUserPWDChange.Text = "Kennwort ändern von Benutzer: "  +$ADUserDaten.Name+  ""

    try
    {
    $txtBoxTSSkript.Text = $TSAD.psbase.InvokeGet("terminalservicesprofilepath")
    $txtBoxTSDriveLetter.Text = $TSAD.psbase.InvokeGet("terminalservicesHomeDrive")
    $txtBoxTSPath.Text = $TSAD.psbase.InvokeGet("terminalservicesHomeDirectory")
    }
    catch
    {
    $txtBoxTSSkript.Text = ""
    $txtBoxTSDriveLetter.Text = ""
    $txtBoxTSPath.Text = ""
    }
    return 0;  

}

function BearbeitungAktivieren
{
    $StatusBox.Enabled = $true
    $txtBoxEmployeeID.ReadOnly = $false
    $txtBoxNachname.ReadOnly = $false
    $txtBoxVorname.ReadOnly = $false
    #$txtBoxSam.ReadOnly = $false
    $txtBoxMail.ReadOnly = $false
    #$txtBoxAlias.ReadOnly = $false
    $txtBoxBeschreibung.ReadOnly = $false
    $txtBoxOffice.ReadOnly = $false
    $txtBoxPhone.ReadOnly = $false
    $txtBoxMobil.ReadOnly = $false
    $txtBoxFax.ReadOnly = $false
    $txtBoxPosition.ReadOnly = $false
    $txtBoxAbteilung.ReadOnly = $false
    $txtBoxFirma.ReadOnly = $false
    $txtBoxEmployeeNr.ReadOnly = $false   
    $txtBoxADSkript.ReadOnly = $false
    $txtBoxADDriveLetter.ReadOnly = $false
    $txtBoxADPath.ReadOnly = $false
    if ($LoadExchangeCMDLets -eq "ja"){ $txtBoxAdExt1.ReadOnly = $false } else { $txtBoxAdExt1.ReadOnly = $true }
    if ($LoadExchangeCMDLets -eq "Ja"){ $txtBoxAdExt2.ReadOnly = $false } else { $txtBoxAdExt2.ReadOnly = $true }
    if ($LoadExchangeCMDLets -eq "Ja"){ $CHKBoxADExt15.Enabled = $true } else { $CHKBoxADExt15.Enabled = $false }
    $txtBoxTSSkript.ReadOnly = $false
    $txtBoxTSDriveLetter.ReadOnly = $false
    $txtBoxTSPath.ReadOnly = $false
    $PWDChange.Enabled = $true

}

function BearbeitungDeaktivieren
{
    $StatusBox.Enabled = $false
    $txtBoxEmployeeID.ReadOnly = $true
    $txtBoxNachname.ReadOnly = $true
    $txtBoxVorname.ReadOnly = $true
    #$txtBoxSam.ReadOnly = $true
    $txtBoxMail.ReadOnly = $true
    $txtBoxAlias.ReadOnly = $true
    $txtBoxBeschreibung.ReadOnly = $true
    $txtBoxOffice.ReadOnly = $true
    $txtBoxPhone.ReadOnly = $true
    $txtBoxMobil.ReadOnly = $true
    $txtBoxFax.ReadOnly = $true
    $txtBoxPosition.ReadOnly = $true
    $txtBoxAbteilung.ReadOnly = $true
    $txtBoxFirma.ReadOnly = $true
    $txtBoxEmployeeNr.ReadOnly = $true
    $CHKBoxADExt15.Enabled = $false
    $txtBoxADSkript.ReadOnly = $true
    $txtBoxADDriveLetter.ReadOnly = $true
    $txtBoxADPath.ReadOnly = $true
    $txtBoxAdExt1.ReadOnly = $true
    $txtBoxAdExt2.ReadOnly = $true
    $txtBoxTSSkript.ReadOnly = $true
    $txtBoxTSDriveLetter.ReadOnly = $true
    $txtBoxTSPath.ReadOnly = $true
    $PWDChange.Enabled = $false
}

function Speichern
{
    
    
    $Fortschritt.Visible = $True
    $Fortschritt.Style = "Marquee"
    $FortschrittText.Text = "...wird gespeichert..."    
    
    $AccountPWD = $txtBoxPWDChange.text                  
    if ($StatusBox.Checked -eq $true) { $Account = $true} else { $Account = $false}
    #if ($PWDChange.Checked -eq $true) { $AccountPWD = $txtBoxPWDChange.text } else {$AccountPWD = $null}
    if ($txtBoxEmployeeID.TextLength -eq "0") { $EmployeeID = $null } else { $EmployeeID = $txtBoxEmployeeID.Text}
    if ($txtBoxNachname.TextLength -eq "0") { $Surname = $null } else { $Surname = $txtBoxNachname.Text}
    if ($txtBoxVorname.TextLength -eq "0") { $GivenName = $null } else { $GivenName = $txtBoxVorname.Text}
    if ($txtBoxMail.TextLength -eq "0") { $Mail = $null } else { $Mail = $txtBoxMail.Text}
    if ($txtBoxAlias.TextLength -eq "0") { $Alias = $null } else { $Alias = $txtBoxAlias.Text}
    if ($txtBoxBeschreibung.TextLength -eq "0") { $Description = $null } else { $Description = $txtBoxBeschreibung.Text}
    if ($txtBoxOffice.TextLength -eq "0") { $Office = $null } else { $Office = $txtBoxOffice.Text}
    if ($txtBoxPhone.TextLength -eq "0") { $telephone = $null } else { $telephone = $txtBoxPhone.Text}
    if ($txtBoxMobil.TextLength -eq "0") { $Mobile = $null } else { $Mobile = $txtBoxMobil.Text}
    if ($txtBoxFax.TextLength -eq "0") { $Fax = $null } else { $Fax = $txtBoxFax.Text}
    if ($txtBoxPosition.TextLength -eq "0") { $title = $null } else { $title = $txtBoxPosition.Text}
    if ($txtBoxAbteilung.TextLength -eq "0") { $Department = $null } else { $Department = $txtBoxAbteilung.Text}
    if ($txtBoxFirma.TextLength -eq "0") { $Company = $null } else { $Company = $txtBoxFirma.Text}
    if ($txtBoxEmployeeNr.TextLength -eq "0") { $EmployeeNR = $null } else { $EmployeeNR = $txtBoxEmployeeNr.Text}
    if ($CHKBoxADExt15.Checked -eq $true) { $Extension3 = "1" } else { $Extension3 = "0" }
    if ($txtBoxADSkript.TextLength -eq "0") { $scriptPath = $null } else { $scriptPath = $txtBoxADSkript.Text}
    if ($txtBoxADDriveLetter.TextLength -eq "0") { $homeDrive = $null } else { $homeDrive = $txtBoxADDriveLetter.Text}
    if ($txtBoxADPath.TextLength -eq "0") { $homeDirectory = $null } else { $homeDirectory = $txtBoxADPath.Text}
    if ($txtBoxAdExt1.TextLength -eq "0") { $Extension1 = " $null" } else { $Extension1 = $txtBoxAdExt1.Text}
    if ($txtBoxAdExt2.TextLength -eq "0") { $Extension2 = " $null" } else { $Extension2 = $txtBoxAdExt2.Text}
    if ($txtBoxTSSkript.TextLength -eq "0") { $TSProfilePath = "$null" } else { $TSProfilePath = $txtBoxTSSkript.Text}
    if ($txtBoxTSDriveLetter.TextLength -eq "0") { $TSHomeDrive = "$null" } else { $TSHomeDrive = $txtBoxTSDriveLetter.Text}
    if ($txtBoxTSPath.TextLength -eq "0") { $TSHomeDirectory = "$null" } else { $TSHomeDirectory = $txtBoxTSPath.Text}

   
    $ADUser = 0;
    $ADUserDaten = 0;
    $ADUser = $UserName.Text
    $ADUserDaten = Get-Aduser $ADUser

    $ADUserDN = $ADUserDaten.DistinguishedName
    $TSAD = [ADSI] "LDAP://$ADUSerDN"

    if ($LoadExchangeCMDLets -eq "Ja")
    {
    Set-ADUser -Server "$ADDCServer" -Identity "$ADUser" -EmployeeID $EmployeeID -Surname $Surname -GivenName $GivenName -EmailAddress $Mail  `
                         -Description $Description -Office $Office -OfficePhone $telephone -mobile $Mobile -Fax $Fax -Title $title -Department $Department -Company $Company -EmployeeNumber $EmployeeNR `
                         -ScriptPath $scriptPath -HomeDrive $homeDrive -HomeDirectory $homeDirectory -Replace @{"Extensionattribute1" = $Extension1; "Extensionattribute2" = $Extension2; "Extensionattribute15" = $Extension3 } -Enabled $Account
    }
    else
    {
    Set-ADUser -Server "$ADDCServer" -Identity "$ADUser" -EmployeeID $EmployeeID -Surname $Surname -GivenName $GivenName -EmailAddress $Mail  `
                         -Description $Description -Office $Office -OfficePhone $telephone -mobile $Mobile -Fax $Fax -Title $title -Department $Department -Company $Company -EmployeeNumber $EmployeeNR `
                         -ScriptPath $scriptPath -HomeDrive $homeDrive -HomeDirectory $homeDirectory -Enabled $Account
    }
    
    if (($PWDChange.Checked -eq $true) -and (!$txtBoxPWDChange.TextLength -eq 0))
    {
        Set-ADAccountPassword "$ADUser" -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "$AccountPWD" -Force)
    }
    if (($PWDChange.Checked -eq $true) -and (!$txtBoxPWDChange.TextLength -eq 0) -and ($PWDChangeNextLogon.Checked -eq $true))
    {
        Set-ADAccountPassword "$ADUser" -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "$AccountPWD" -Force)
        Set-ADUser "$ADUser" -ChangePasswordAtLogon:$true
    }
                      
    try { $TSAD.psbase.InvokeSet("terminalservicesprofilepath", $TSProfilePath) } catch { echo $null }   
    try { $TSAD.psbase.InvokeSet("terminalservicesHomeDrive", $TSHomeDrive) } catch { echo $null }
    try { $TSAD.psbase.InvokeSet("terminalservicesHomeDirectory", $TSHomeDirectory) } catch { echo $null }
    $TSAD.setInfo()
    
    Start-Sleep -s 10

   

    
    $Fortschritt.Visible = $True
    $Fortschritt.Value = 100
    $Fortschritt.Style = "Continuous"
    $FortschrittText.Text = "Daten gespeichert"     
}

function Referenz
{
    
    $membership.Items.Clear();

    $ADUser = 0;
    $ADUserDaten = 0;
    $ADUser = $UserName.Text



     if (($Username.text.Length -eq 0) -or (!(dsquery user -samid $ADUser)))

        {
        $KeinBenutzer = [Windows.Forms.MessageBox]
        $KeinBenutzer::Show("Es wurde kein Referenz Benutzer angegeben, bitte in den ersten Reiter wechseln und einen Benutzer abfragen" , "Kein Referenz Benutzer angegeben", "OK", "Error") 
        return 0;
        exit;
        }
       
    if ($LoadExchangeCMDLets -eq "Ja")
    {
    $ADUserDaten = Get-Aduser -Server $ADDCServer -Identity "$ADUser" -Properties employeeID, employeeNumber, Surname, GivenName, SamAccountName, Mail, 
                                   Description, Office, telephoneNumber, mobile, facsimileTelephoneNumber, title, department, Company,
                                   scriptPath, homeDrive, homeDirectory,extensionAttribute1, extensionAttribute2, extensionAttribute15, UserPrincipalName
     if ($ADUserDaten.extensionAttribute15 -eq "1"){ $CHKBoxADExt15Change.Checked = $true }else{ $CHKBoxADExt15Change.Checked = $false }  
    
    }
    else
    {
    $ADUserDaten = Get-Aduser -Server $ADDCServer -Identity "$ADUser" -Properties employeeID, employeeNumber, Surname, GivenName, SamAccountName, Mail, 
                                   Description, Office, telephoneNumber, mobile, facsimileTelephoneNumber, title, department, Company,
                                   scriptPath, homeDrive, homeDirectory, UserPrincipalName
    }
     
    
    $DN = $ADUserDaten.DistinguishedName
    $PATH = $DN.substring($dn.IndexOf("OU=")).split(".")
    #$PATH
    
    $ADUserDN = $ADUserDaten.DistinguishedName
    $TSAD = [ADSI] "LDAP://$ADUSerDN"
       
    
    #$txtBoxEmployeeIDCreate.text = $ADUserDaten.EmployeeID
    $txtBoxNachnameCreate.text = $ADUserDaten.Surname
    $txtBoxVornameCreate.text = $ADUserDaten.GivenName
    $txtBoxNTCreate.text = "Neuen Benutzernamen eingeben"
    $txtBoxUPNCreate.text = "Neuen Benutzernamen eingeben"
    $txtBoxOU.text = $PATH
    $txtBoxBeschreibungCreate.text = $ADUserDaten.Description
    $txtBoxOfficeCreate.text = $ADUserDaten.Office
    $txtBoxPhoneCreate.text = $ADUserDaten.telephoneNumber
    $txtBoxMobilCreate.text = $ADUserDaten.Mobile
    $txtBoxFaxCreate.text = $ADUserDaten.facsimileTelephoneNumber
    $txtBoxPositionCreate.text = $ADUserDaten.Title
    $txtBoxAbteilungCreate.text = $ADUserDaten.Department
    $txtBoxFirmaCreate.text = $ADUserDaten.Company
    $txtBoxEmployeeNrCreate.text = $ADUserDaten.EmployeeNumber
    $txtBoxADSkriptCreate.text = $ADUserDaten.ScriptPath
    $txtBoxADDriveLetterCreate.text = $ADUserDaten.HomeDrive
    $txtBoxADPathCreate.text = $ADUserDaten.HomeDirectory
    $txtBoxPWD.Text = "'Kennwort'"
    $txtBoxAdExt1Create.text = $ADUserDaten.extensionAttribute1
    $txtBoxAdExt2Create.text = $ADUserDaten.extensionAttribute2
    
    
        $Groups = (Get-ADPrincipalGroupMembership $ADUser)
        foreach($group in $Groups)
        {
        $membership.items.add($group.samAccountName)
        }

        $GRPsAnzahl = $Groups.Count
        $BTNSelectAll.Text = "Alle auswählen (" + $GRPsAnzahl + ")"
   
    try
    {
    $txtBoxTSSkriptCreate.Text = $TSAD.psbase.InvokeGet("terminalservicesprofilepath")
    $txtBoxTSDriveLetterCreate.Text = $TSAD.psbase.InvokeGet("terminalservicesHomeDrive")
    $txtBoxTSPathCreate.Text = $TSAD.psbase.InvokeGet("terminalservicesHomeDirectory")
    }
    catch
    {
    $txtBoxTSSkript.Text = ""
    $txtBoxTSDriveLetter.Text = ""
    $txtBoxTSPath.Text = ""
    }
    return 0;  
}

function SelectAllGroups #( $checkedListBoxObject )
{   
    For($index =0; $index -lt $membership.Items.Count; $index++){ $membership.SetItemChecked($index, $true)}
}

function NeuerBenutzer
{
    $Domain = Get-ADDomain
    $UPNDom = $Domain.DnsRoot 

    $OU = $txtBoxOU.Text
    $AccountPWD = $txtBoxPWD.text
    $SAM = $txtBoxNTCreate.Text
    $UPN = $txtBoxUPNCreate.Text                  
  
    if ($txtBoxPWD.TextLength-eq "0") { $AccountPWD = $null } else {$AccountPWD = $txtBoxPWD.text}
    if ($txtBoxEmployeeIDCreate.TextLength -eq "0") { $EmployeeID = $null } else { $EmployeeID = $txtBoxEmployeeIDCreate.Text}
    if ($txtBoxNachnameCreate.TextLength -eq "0") { $Surname = $null } else { $Surname = $txtBoxNachnameCreate.Text}
    if ($txtBoxVornameCreate.TextLength -eq "0") { $GivenName = $null } else { $GivenName = $txtBoxVornameCreate.Text}
    if ($txtBoxBeschreibungCreate.TextLength -eq "0") { $Description = $null } else { $Description = $txtBoxBeschreibungCreate.Text}
    if ($txtBoxOfficeCreate.TextLength -eq "0") { $Office = $null } else { $Office = $txtBoxOfficeCreate.Text}
    if ($txtBoxPhoneCreate.TextLength -eq "0") { $telephone = $null } else { $telephone = $txtBoxPhoneCreate.Text}
    if ($txtBoxMobilCreate.TextLength -eq "0") { $Mobile = $null } else { $Mobile = $txtBoxMobilCreate.Text}
    if ($txtBoxFaxCreate.TextLength -eq "0") { $Fax = $null } else { $Fax = $txtBoxFaxCreate.Text}
    if ($txtBoxPositionCreate.TextLength -eq "0") { $title = $null } else { $title = $txtBoxPositionCreate.Text}
    if ($txtBoxAbteilungCreate.TextLength -eq "0") { $Department = $null } else { $Department = $txtBoxAbteilungCreate.Text}
    if ($txtBoxFirmaCreate.TextLength -eq "0") { $Company = $null } else { $Company = $txtBoxFirmaCreate.Text}
    if ($txtBoxEmployeeNrCreate.TextLength -eq "0") { $EmployeeNR = $null } else { $EmployeeNR = $txtBoxEmployeeNrCreate.Text}
    if ($CHKBoxADExt15Change.Checked -eq $true) { $Extension3 = "1" } else { $Extension3 = "0" }
    if ($txtBoxAdExt1Create.TextLength -eq "0") { $Extension1 = " $null" } else { $Extension1 = $txtBoxAdExt1Create.Text}
    if ($txtBoxAdExt2Create.TextLength -eq "0") { $Extension2 = " $null" } else { $Extension2 = $txtBoxAdExt2Create.Text}
    if ($txtBoxADSkriptCreate.TextLength -eq "0") { $scriptPath = $null } else { $scriptPath = $txtBoxADSkriptCreate.Text}
    if ($txtBoxADDriveLetterCreate.TextLength -eq "0") { $homeDrive = $null } else { $homeDrive = $txtBoxADDriveLetterCreate.Text}
    if ($txtBoxADPathCreate.TextLength -eq "0") { $homeDirectory = $null } else { $homeDirectory = $txtBoxADPathCreate.Text}
    if ($txtBoxTSSkriptCreate.TextLength -eq "0") { $TSProfilePath = "$null" } else { $TSProfilePath = $txtBoxTSSkriptCreate.Text}
    if ($txtBoxTSDriveLetterCreate.TextLength -eq "0") { $TSHomeDrive = "$null" } else { $TSHomeDrive = $txtBoxTSDriveLetterCreate.Text}
    if ($txtBoxTSPathCreate.TextLength -eq "0") { $TSHomeDirectory = "$null" } else { $TSHomeDirectory = $txtBoxTSPathCreate.Text}
    if ($PWDmustChange.Checked -eq $true) { $PWDAtLogon = $true } else { $PWDAtLogon = $false}
    if ($PWDablauf.Checked -eq $true) { $PWDExpires = $true } else { $PWDExpires = $false}
    
    #Sicherheitsabfrage ob es den Benutzer mit dem SamAccount schon gibt

    if (!(dsquery user -samid $SAM))
    {
        $Fortschritt.Visible = $True
        $Fortschritt.Style = "Marquee"
        $FortschrittText.Text = "...wird gespeichert..."
        if ($LoadExchangeCMDLets -eq "Ja")
        {
        New-ADUser -Name ($Surname + ", " + $GivenName) -EmployeeID $EmployeeID -Surname $Surname -GivenName $GivenName -SamAccountName $SAM -UserPrincipalName  ($UPN + "@" + $UPNDom) -DisplayName ($Surname + ", " + $GivenName)  `
                         -Description $Description -Office $Office -OfficePhone $telephone -mobile $Mobile -Fax $Fax -Title $title -Department $Department -Company $Company -EmployeeNumber $EmployeeNR `
                         -ScriptPath $scriptPath -HomeDrive $homeDrive -HomeDirectory $homeDirectory  -Path $OU `
                         -AccountPassword (ConvertTo-SecureString -AsPlainText $AccountPWD -Force) -Enabled $true  -ChangePasswordAtLogon $PWDAtLogon -PasswordNeverExpires $PWDExpires `
                         -OtherAttributes @{"Extensionattribute1" = $Extension1; "Extensionattribute2" = $Extension2; "Extensionattribute15" = $Extension3 }
                          
        }
        else
        {
        New-ADUser -Name ($Surname + ", " + $GivenName) -EmployeeID $EmployeeID -Surname $Surname -GivenName $GivenName -SamAccountName $SAM -UserPrincipalName  ($UPN + "@" + $UPNDom) -DisplayName ($Surname + ", " + $GivenName)  `
                         -Description $Description -Office $Office -OfficePhone $telephone -mobile $Mobile -Fax $Fax -Title $title -Department $Department -Company $Company -EmployeeNumber $EmployeeNR `
                         -ScriptPath $scriptPath -HomeDrive $homeDrive -HomeDirectory $homeDirectory  -Path $OU `
                         -AccountPassword (ConvertTo-SecureString -AsPlainText $AccountPWD -Force) -Enabled $true  -ChangePasswordAtLogon $PWDAtLogon -PasswordNeverExpires $PWDExpires
                         
        }

    }        
        else
        {
        $BenutzerExist = [Windows.Forms.MessageBox]
        $BenutzerExist::Show("Diesen Benutzernamen gibt es schon!" , "Benutzer existiert Bereits", "OK", "Error") 
        $Fortschritt.Visible = $false
        $FortschrittText.Text = "Keine Daten gespeichert"
        return 0;
        exit NeuerBenutzer;
         
        }
        
    
    
    Start-Sleep -s 15
        
    $ADUser = 0;
    $ADUserDaten = 0;
    $ADUser = $txtBoxNTCreate.Text
    $ADUserDaten = Get-Aduser $ADUser
    $UseDatabase = if ($DatabaseAutoSelect.Checked -eq $true) {$null} else { $DatabaseName.Text }
    $UseABPolicy = if ($CHKBoxABPolicy.Checked -eq $true) {$ABPolicy.Text} else {$null}
    $UseEASpolicy = if ($CHKBoxEASPolicy.Checked -eq $true) {$EASPolicy.Text} else { $null}
    $UseRolePolicy = if ($CHKBoxrolePolicy.CheckAlign -eq $true) {$RolePolicy.Text} else { $null}
    
    if ($CHKBoxExchangeMailbox.Checked -eq $true) {Get-User "$ADUser" | Enable-Mailbox -AddressBookPolicy $UseABPolicy -ActiveSyncMailboxPolicy $UseEASpolicy -RoleAssignmentPolicy $UseRolePolicy -Database $UseDatabase}
       
    #Überprüfen welche Haken gesetzt sind
    $ArrayGroups = $membership.checkeditems
    
    #Benutzer zu jeder Gruppe davon hinzufügen
    foreach($group in $ArrayGroups)
    {
    Add-ADGroupMember -Identity "$group" -Members $ADUser
    }

    #Benutzer kennwort auf Kennwort kann nciht geändert werden setzen
    if ($PWDcantChange.Checked -eq $true)
    {
    Set-ADAccountControl -Identity $ADUser -CannotChangePassword:$true
    }


    $ADUserDN = $ADUserDaten.DistinguishedName
    $TSAD = [ADSI] "LDAP://$ADUSerDN"
                               
    try { $TSAD.psbase.InvokeSet("terminalservicesprofilepath", $TSProfilePath) } catch { echo $null }   
    try { $TSAD.psbase.InvokeSet("terminalservicesHomeDrive", $TSHomeDrive) } catch { echo $null }
    try { $TSAD.psbase.InvokeSet("terminalservicesHomeDirectory", $TSHomeDirectory) } catch { echo $null }
    $TSAD.setInfo()
       
    $Fortschritt.Visible = $True
    $Fortschritt.Value = 100
    $Fortschritt.Style = "Continuous"
    $FortschrittText.Text = "Daten gespeichert"     
}

function FelderReset
{
    $txtBoxOU.Text = "$OUSearch"
    $txtBoxVornameCreate.Text = "'Vorname'"
    $txtBoxNachnameCreate.Text = "'Nachname'"
    $txtBoxUPNCreate.Text = "'Benutzeranmeldename'"
    $txtBoxNTCreate.Text = "'NT Benutzeranmeldename'"
    $txtBoxBeschreibungCreate.Text = "'Beschreibung'"
    $txtBoxOfficeCreate.Text = "'Büro'"
    $txtBoxPhoneCreate.Text = "'Telefon'"
    $txtBoxMobilCreate.Text = "'Mobilfunk'"
    $txtBoxFaxCreate.Text = "'Fax'"
    $txtBoxPositionCreate.Text = "'Position'"
    $txtBoxAbteilungCreate.Text = "'Abteilung'"
    $txtBoxFirmaCreate.Text = "'Firma'"
    $txtBoxEmployeeIDCreate.Text = "'EmployeeID'"
    $txtBoxEmployeeNrCreate.Text = "'Employee Number / Kostenstelle'"
    $txtBoxPWD.Text = "'Kennwort'"
    $txtBoxADSkriptCreate.Text = "'AD Anmeldeskript'"
    $txtBoxADDriveLetterCreate.Text = "'?:'"
    $txtBoxADPathCreate.Text = "'Profilpfad'"
    $txtBoxTSSkriptCreate.Text = "'Terminalservice Skript'"
    $txtBoxTSDriveLetterCreate.Text = "'?:'"
    $txtBoxTSPathCreate.Text = "'Profilpfad'"
    $BTNSelectAll.Text = "Alle auswählen"
}    


function Abmelden {
                
                Remove-PSSession -Name Exchange               
                $Fenster1.Close()
                
                
         } # Beendet die Funktion Abmelden   

# Gruppenbox fuer Benutzer-Mailbox
$GroupBoxUser = New-Object System.Windows.Forms.GroupBox
$GroupBoxUser.Location = New-Object System.Drawing.Size(10,10)
$GroupBoxUser.size = New-Object System.Drawing.Size(350,70) 
$GroupBoxUser.Font = $Font
$GroupBoxUser.Text = "Benutzernamen angeben"
$TabUserEdit.Controls.Add($GroupBoxUser)

# Gruppenbox fuer OU und Benutzerstatus
$GroupBoxUserOU = New-Object System.Windows.Forms.GroupBox
$GroupBoxUserOU.Location = New-Object System.Drawing.Size(10,90)
$GroupBoxUserOU.size = New-Object System.Drawing.Size(350,75) 
$GroupBoxUserOU.Font = $Font
$GroupBoxUserOu.Text = "OU / Benutzerstatus"
$TabUserEdit.Controls.Add($GroupBoxUserOU )

# Gruppenbox fuer Stammdaten
$GroupBoxUserData1 = New-Object System.Windows.Forms.GroupBox
$GroupBoxUserData1.Location = New-Object System.Drawing.Size(10,170)
$GroupBoxUserData1.size = New-Object System.Drawing.Size(350,200) 
$GroupBoxUserData1.Font = $Font
$GroupBoxUserData1.Text = "Stammdaten von Benutzer:"
$TabUserEdit.Controls.Add($GroupBoxUserData1)

# Gruppenbox fuer Organisationsdaten
$GroupBoxUserData2 = New-Object System.Windows.Forms.GroupBox
$GroupBoxUserData2.Location = New-Object System.Drawing.Size(380,10)   #380,10
$GroupBoxUserData2.size = New-Object System.Drawing.Size(350,320) 
$GroupBoxUserData2.Font = $Font
$GroupBoxUserData2.Text = "Organisationsdaten von Benutzer:"
$TabUserEdit.Controls.Add($GroupBoxUserData2)

# Gruppenbox fuer Kennwort ändern
$GroupBoxUserPWDChange = New-Object System.Windows.Forms.GroupBox
$GroupBoxUserPWDChange.Location = New-Object System.Drawing.Size(380,340)   
$GroupBoxUserPWDChange.size = New-Object System.Drawing.Size(350,160) 
$GroupBoxUserPWDChange.Font = $Font
$GroupBoxUserPWDChange.Text = "Kennwort ändern:"
$TabUserEdit.Controls.Add($GroupBoxUserPWDChange)

# Gruppenbox fuer AD-Profil
$GroupBoxUserData3 = New-Object System.Windows.Forms.GroupBox
$GroupBoxUserData3.Location = New-Object System.Drawing.Size(10,375) #10,300
$GroupBoxUserData3.size = New-Object System.Drawing.Size(350,180) 
$GroupBoxUserData3.Font = $Font
$GroupBoxUserData3.Text = "AD-Profil von Benutzer:"
$TabUserEdit.Controls.Add($GroupBoxUserData3)

# Gruppenbox fuer Terminalservice-Profil
$GroupBoxUserData4 = New-Object System.Windows.Forms.GroupBox
$GroupBoxUserData4.Location = New-Object System.Drawing.Size(10,557)
$GroupBoxUserData4.size = New-Object System.Drawing.Size(350,180) 
$GroupBoxUserData4.Font = $Font
$GroupBoxUserData4.Text = "Terminalservice von Benutzer:"
$TabUserEdit.Controls.Add($GroupBoxUserData4)

# Gruppenbox fuer Bearbeitung aktivieren
$GroupBoxBearbeitung = New-Object System.Windows.Forms.GroupBox
$GroupBoxBearbeitung.Location = New-Object System.Drawing.Size(380,510)
$GroupBoxBearbeitung.size = New-Object System.Drawing.Size(350,80) 
$GroupBoxBearbeitung.Font = $Font
$GroupBoxBearbeitung.Text = "Bearbeitung aktivieren...?"
$TabUserEdit.Controls.Add($GroupBoxBearbeitung)

# Gruppenbox fuer Speichern
$GroupBoxSpeichern = New-Object System.Windows.Forms.GroupBox
$GroupBoxSpeichern.Location = New-Object System.Drawing.Size(380,600)
$GroupBoxSpeichern.size = New-Object System.Drawing.Size(350,80) 
$GroupBoxSpeichern.Font = $Font
$GroupBoxSpeichern.Text = "Aktualisierte Daten speichern"
$TabUserEdit.Controls.Add($GroupBoxSpeichern)

# Gruppenbox fuer Benutzer-Erstellen Kontodaten
$GroupBoxUserCreate = New-Object System.Windows.Forms.GroupBox
$GroupBoxUserCreate.Location = New-Object System.Drawing.Size(10,10)
$GroupBoxUserCreate.size = New-Object System.Drawing.Size(720,175) 
$GroupBoxUserCreate.Font = $Font
$GroupBoxUserCreate.Text = "Benutzer anlegen - Kontodaten"
$TabUserCreate.Controls.Add($GroupBoxUserCreate)

# Gruppenbox fuer Benutzer-Erstellen Orgdaten
$GroupBoxUserCreateOrg = New-Object System.Windows.Forms.GroupBox
$GroupBoxUserCreateOrg.Location = New-Object System.Drawing.Size(10,255)
$GroupBoxUserCreateOrg.size = New-Object System.Drawing.Size(350,345) 
$GroupBoxUserCreateOrg.Font = $Font
$GroupBoxUserCreateOrg.Text = "Benutzer anlegen - Organisationsdaten"
$TabUserCreate.Controls.Add($GroupBoxUserCreateOrg)

# Gruppenbox fuer Benutzer-Erstellen Kontooptionen
$GroupBoxAccount = New-Object System.Windows.Forms.GroupBox
$GroupBoxAccount.Location = New-Object System.Drawing.Size(380,255)
$GroupBoxAccount.size = New-Object System.Drawing.Size(350,160) 
$GroupBoxAccount.Font = $Font
$GroupBoxAccount.Text = "Benutzer anlegen - Kontooptionen"
$TabUserCreate.Controls.Add($GroupBoxAccount)

#Gruppenbox für Gruppen hinzufügen
$GroupBoxGroups = New-Object System.Windows.Forms.GroupBox
$GroupBoxGroups.Location = New-Object System.Drawing.Size(380,420)
$GroupBoxGroups.size = New-Object System.Drawing.Size(350,180) 
$GroupBoxGroups.Font = $Font
$GroupBoxGroups.Text = "Benutzer anlegen - AD Gruppen"
$TabUserCreate.Controls.Add($GroupBoxGroups)

# Gruppenbox fuer Benutzer-Erstellen AD-Profil Erstellen
$GroupBoxADProfil = New-Object System.Windows.Forms.GroupBox
$GroupBoxADProfil.Location = New-Object System.Drawing.Size(10,190)
$GroupBoxADProfil.size = New-Object System.Drawing.Size(720,60) 
$GroupBoxADProfil.Font = $Font
$GroupBoxADProfil.Text = "Benutzer anlegen - Profiloptionen"
$TabUserCreate.Controls.Add($GroupBoxADProfil)

# Gruppenbox fuer Benutzer-Erstellen TS-Profil Erstellen
$GroupBoxTSProfil = New-Object System.Windows.Forms.GroupBox
$GroupBoxTSProfil.Location = New-Object System.Drawing.Size(10,610)
$GroupBoxTSProfil.size = New-Object System.Drawing.Size(720,60) 
$GroupBoxTSProfil.Font = $Font
$GroupBoxTSProfil.Text = "Benutzer anlegen - Terminalserver Profil"
$TabUserCreate.Controls.Add($GroupBoxTSProfil)

# Gruppenbox fuer Benutzer-Erstellen Exchange-Optionen
$GroupBoxExchange = New-Object System.Windows.Forms.GroupBox
$GroupBoxExchange.Location = New-Object System.Drawing.Size(750,80)
$GroupBoxExchange.size = New-Object System.Drawing.Size(350,400) 
$GroupBoxExchange.Font = $Font
$GroupBoxExchange.Text = "Benutzer anlegen - Exchange"
$TabUserCreate.Controls.Add($GroupBoxExchange)

# Stammdaten Text Anzeigen lassen
$StammdatenCreate = New-Object System.Windows.Forms.Label
$StammdatenCreate.Location = New-Object System.Drawing.Size(10,25)
$StammdatenCreate.Size =New-Object System.Drawing.Size(150,140)
$StammdatenCreate.Text = "Erstellen in OU:
 
Vorname

Nachname

UserPrinipalName

samAccountName"
$GroupBoxUserCreate.Controls.Add($StammdatenCreate)

#Textfeld OU
$txtBoxOU = New-Object System.Windows.Forms.Textbox
$txtBoxOU.Location = New-Object System.Drawing.Size(160,22)
$txtBoxOU.Size = New-Object System.Drawing.Size(550,15)
$txtBoxOU.Text = "$OUSearch"
$txtBoxOU.ReadOnly = $false
$txtBoxOU.TabIndex = 1
$GroupBoxUserCreate.Controls.Add($txtBoxOU)

# OU auswählen
$OUAbfragen = New-Object System.Windows.Forms.Button
$OUAbfragen.Location = New-Object System.Drawing.Size(470,22)
$OUAbfragen.Size = New-Object System.Drawing.Size(100,22)
$OUAbfragen.Text = "OU auwählen"
$OUAbfragen.TabIndex = 5
$OUAbfragen.BackColor = "white"
$OUAbfragen.Add_Click({OUAbfrage})
#$GroupBoxUserCreate.Controls.Add($OUAbfragen)

#Textbox Benutzernamen angeben zum erstellen vorname
$txtBoxVornameCreate = New-Object System.Windows.Forms.Textbox
$txtBoxVornameCreate.Location = New-Object System.Drawing.Size(160,52)
$txtBoxVornameCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxVornameCreate.Text = "'Vorname'"
$txtBoxVornameCreate.ReadOnly = $false
$txtBoxVornameCreate.TabIndex = 1
$GroupBoxUserCreate.Controls.Add($txtBoxVornameCreate)

$txtBoxNachnameCreate = New-Object System.Windows.Forms.Textbox
$txtBoxNachnameCreate.Location = New-Object System.Drawing.Size(160,82)
$txtBoxNachnameCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxNachnameCreate.Text = "'Nachname'"
$txtBoxNachnameCreate.ReadOnly = $false
$txtBoxNachnameCreate.TabIndex = 1
$GroupBoxUserCreate.Controls.Add($txtBoxNachnameCreate)

$txtBoxUPNCreate = New-Object System.Windows.Forms.Textbox
$txtBoxUPNCreate.Location = New-Object System.Drawing.Size(160,112)
$txtBoxUPNCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxUPNCreate.Text = "'Benutzeranmeldename'"
$txtBoxUPNCreate.ReadOnly = $false
$txtBoxUPNCreate.TabIndex = 1
$GroupBoxUserCreate.Controls.Add($txtBoxUPNCreate)

$txtUPN = New-Object System.Windows.Forms.Label
$txtUPN.Location = New-Object System.Drawing.Size(345,112)
$txtUPN.Size = New-Object System.Drawing.Size(180,20)
$txtUPN.Text = "@$ADDNSRoot"
#$txtBoxUPNCreate.ReadOnly = $true
$txtUPN.TabIndex = 1
$GroupBoxUserCreate.Controls.Add($txtUPN)

$txtNT = New-Object System.Windows.Forms.Label
$txtNT.Location = New-Object System.Drawing.Size(160,147)
$txtNT.Size = New-Object System.Drawing.Size(110,20)
$txtNT.Text = "$ADNetBIOSName\"
#$txtBoxUPNCreate.ReadOnly = $true
$txtNT.TabIndex = 1
$GroupBoxUserCreate.Controls.Add($txtNT)

$txtBoxNTCreate = New-Object System.Windows.Forms.Textbox
$txtBoxNTCreate.Location = New-Object System.Drawing.Size(270,142)
$txtBoxNTCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxNTCreate.Text = "'NT Benutzeranmeldename'"
$txtBoxNTCreate.ReadOnly = $false
$txtBoxNTCreate.TabIndex = 1
$GroupBoxUserCreate.Controls.Add($txtBoxNTCreate)

# Organisationsdaten Text Anzeigen lassen
$OrgdatenCreate = New-Object System.Windows.Forms.Label
$OrgdatenCreate.Location = New-Object System.Drawing.Size(10,25)
$OrgdatenCreate.Size =New-Object System.Drawing.Size(150,295)
$OrgdatenCreate.Text = "Beschreibung

Büro

Rufnummer

Mobil

Fax

Position

Abteilung

Firma

GID

Kostenstelle"
$GroupBoxUserCreateOrg.Controls.Add($OrgdatenCreate)


$txtBoxBeschreibungCreate = New-Object System.Windows.Forms.Textbox
$txtBoxBeschreibungCreate.Location = New-Object System.Drawing.Size(160,22)
$txtBoxBeschreibungCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxBeschreibungCreate.Text = "'Beschreibung'"
$txtBoxBeschreibungCreate.ReadOnly = $false
$txtBoxBeschreibungCreate.TabIndex = 1
$GroupBoxUserCreateOrg.Controls.Add($txtBoxBeschreibungCreate)

$txtBoxOfficeCreate = New-Object System.Windows.Forms.Textbox
$txtBoxOfficeCreate.Location = New-Object System.Drawing.Size(160,52)
$txtBoxOfficeCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxOfficeCreate.Text = "'Büro'"
$txtBoxOfficeCreate.ReadOnly = $false
$txtBoxOfficeCreate.TabIndex = 1
$GroupBoxUserCreateOrg.Controls.Add($txtBoxOfficeCreate)

$txtBoxPhoneCreate = New-Object System.Windows.Forms.Textbox
$txtBoxPhoneCreate.Location = New-Object System.Drawing.Size(160,82)
$txtBoxPhoneCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxPhoneCreate.Text = "'Telefon'"
$txtBoxPhoneCreate.ReadOnly = $false
$txtBoxPhoneCreate.TabIndex = 1
$GroupBoxUserCreateOrg.Controls.Add($txtBoxPhoneCreate)

$txtBoxMobilCreate = New-Object System.Windows.Forms.Textbox
$txtBoxMobilCreate.Location = New-Object System.Drawing.Size(160,112)
$txtBoxMobilCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxMobilCreate.Text = "'Mobilfunk'"
$txtBoxMobilCreate.ReadOnly = $false
$txtBoxMobilCreate.TabIndex = 1
$GroupBoxUserCreateOrg.Controls.Add($txtBoxMobilCreate)

$txtBoxFaxCreate = New-Object System.Windows.Forms.Textbox
$txtBoxFaxCreate.Location = New-Object System.Drawing.Size(160,142)
$txtBoxFaxCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxFaxCreate.Text = "'Fax'"
$txtBoxFaxCreate.ReadOnly = $false
$txtBoxFaxCreate.TabIndex = 1
$GroupBoxUserCreateOrg.Controls.Add($txtBoxFaxCreate)

$txtBoxPositionCreate = New-Object System.Windows.Forms.Textbox
$txtBoxPositionCreate.Location = New-Object System.Drawing.Size(160,172)
$txtBoxPositionCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxPositionCreate.Text = "'Position'"
$txtBoxPositionCreate.ReadOnly = $false
$txtBoxPositionCreate.TabIndex = 1
$GroupBoxUserCreateOrg.Controls.Add($txtBoxPositionCreate)

$txtBoxAbteilungCreate = New-Object System.Windows.Forms.Textbox
$txtBoxAbteilungCreate.Location = New-Object System.Drawing.Size(160,202)
$txtBoxAbteilungCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxAbteilungCreate.Text = "'Abteilung'"
$txtBoxAbteilungCreate.ReadOnly = $false
$txtBoxAbteilungCreate.TabIndex = 1
$GroupBoxUserCreateOrg.Controls.Add($txtBoxAbteilungCreate)

$txtBoxFirmaCreate = New-Object System.Windows.Forms.Textbox
$txtBoxFirmaCreate.Location = New-Object System.Drawing.Size(160,232)
$txtBoxFirmaCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxFirmaCreate.Text = "'Firma'"
$txtBoxFirmaCreate.ReadOnly = $false
$txtBoxFirmaCreate.TabIndex = 1
$GroupBoxUserCreateOrg.Controls.Add($txtBoxFirmaCreate)

$txtBoxEmployeeIDCreate = New-Object System.Windows.Forms.Textbox
$txtBoxEmployeeIDCreate.Location = New-Object System.Drawing.Size(160,262)
$txtBoxEmployeeIDCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxEmployeeIDCreate.Text = "'GID'"
$txtBoxEmployeeIDCreate.ReadOnly = $false
$txtBoxEmployeeIDCreate.TabIndex = 1
$GroupBoxUserCreateOrg.Controls.Add($txtBoxEmployeeIDCreate)

$txtBoxEmployeeNrCreate = New-Object System.Windows.Forms.Textbox
$txtBoxEmployeeNrCreate.Location = New-Object System.Drawing.Size(160,292)
$txtBoxEmployeeNrCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxEmployeeNrCreate.Text = "'Kostenstelle'"
$txtBoxEmployeeNrCreate.ReadOnly = $false
$txtBoxEmployeeNrCreate.TabIndex = 1
$GroupBoxUserCreateOrg.Controls.Add($txtBoxEmployeeNrCreate)

# Checkbox auch für TFP / Benutzerdefiniertes Attribut 15
$CHKBoxADExt15Change = New-Object System.Windows.Forms.CheckBox
$CHKBoxADExt15Change.Location = New-Object System.Drawing.Size(10,322)
$CHKBoxADExt15Change.Size = New-Object System.Drawing.Size(300,20)
$CHKBoxADExt15Change.Text = "$AdExt15"
$CHKBoxADExt15Change.Enabled = if ($LoadExchangeCMDLets -eq "Ja") { $true } else { $false }
$CHKBoxADExt15Change.Checked = if ($LoadExchangeCMDLets -eq "Ja") { $true } else { $false }
$CHKBoxADExt15Change.TabIndex = 1
$GroupBoxUserCreateOrg.Controls.Add($CHKBoxADExt15Change) 

# Checkbox auch für Kennwort muss geändert werden
$PWDmustChange = New-Object System.Windows.Forms.CheckBox
$PWDmustChange.Location = New-Object System.Drawing.Size(10,25)
$PWDmustChange.Size = New-Object System.Drawing.Size(300,40)
$PWDmustChange.Text = "Benutzer muss Kennwort bei der nächsten Anmeldung ändern"
$PWDmustChange.TabIndex = 1
$PWDmustChange.add_Click($handlerPWDOptions)
$GroupBoxAccount.Controls.Add($PWDmustChange) 

# Checkbox auch für Kennwort kann nicht gändert werden
$PWDcantChange = New-Object System.Windows.Forms.CheckBox
$PWDcantChange.Location = New-Object System.Drawing.Size(10,70)
$PWDcantChange.Size = New-Object System.Drawing.Size(300,20)
$PWDcantChange.Text = "Benutzer kann Kennwort nicht ändern"
$PWDcantChange.TabIndex = 1
$PWDcantChange.add_Click($handlerPWDOptions1)
$GroupBoxAccount.Controls.Add($PWDcantChange) 

# Checkbox auch für Kennwort läuft nie ab
$PWDablauf = New-Object System.Windows.Forms.CheckBox
$PWDablauf.Location = New-Object System.Drawing.Size(10,100)
$PWDablauf.Size = New-Object System.Drawing.Size(300,20)
$PWDablauf.Text = "Kennwort läuft nie ab"
$PWDablauf.TabIndex = 1
$PWDablauf.add_Click($handlerPWDOptions)
$GroupBoxAccount.Controls.Add($PWDablauf) 

#Textfeld für Kennwort
$txtBoxPWD = New-Object System.Windows.Forms.Textbox
$txtBoxPWD.Location = New-Object System.Drawing.Size(10,130)
$txtBoxPWD.Size = New-Object System.Drawing.Size(180,15)
$txtBoxPWD.Text = "'Kennwort'"
$txtBoxPWD.ReadOnly = $false
$txtBoxPWD.TabIndex = 1
$GroupBoxAccount.Controls.Add($txtBoxPWD)

#Gruppenmitgliedschaften anzeigen lassen und checkboxen setzen
$membership = New-Object System.Windows.Forms.CheckedListBox
$membership.Location = New-Object System.Drawing.Size(10,20)
$membership.Size = New-Object System.Drawing.Size(330,140)
$membership.DataBindings.DefaultDataSourceUpdateMode = 0
$membership.FormattingEnabled = $True
$membership.Name = "membership"
$membership.Sorted = $true
$membership.CheckOnClick = $true

$membership.TabIndex = 8
$GroupBoxGroups.Controls.Add($membership)

#Button select all
$BTNSelectAll = New-Object System.Windows.Forms.Button
$BTNSelectAll.Location = New-Object System.Drawing.Size(10,155)
$BTNSelectAll.Size = New-Object System.Drawing.Size(140,22)
$BTNSelectAll.Text = "Alle auswählen"
$BTNSelectAll.TabIndex = 18
$BTNSelectAll.BackColor = "white"
$BTNSelectAll.Add_Click({SelectAllGroups})
$GroupBoxGroups.Controls.Add($BTNSelectAll)

#Vorschlagsliste für Benutzereingabefelfd für Benutzernamen
$UserName = New-Object System.Windows.Forms.Combobox
$UserArray = get-aduser -Filter * -SearchBase "$OUSearch" -Properties samAccountName | sort-object
foreach($user in $UserArray) {$UserName.items.add($user.samAccountName) }
$UserName.Location = New-Object System.Drawing.Size(10,20)
$UserName.Size = New-Object System.Drawing.Size(200,20)
$UserName.TabIndex = 4
$UserName.AutoCompleteMode = 3
$UserName.AutoCompleteSource = 256
$UserName.DataBindings.DefaultDataSourceUpdateMode = 0
$UserName.FormattingEnabled = $True
$UserName.Enabled = $True
$GroupBoxUser.Controls.Add($UserName)

#OU und Abgemeldet der Benutzer? 
$ADOUTxt = New-Object System.Windows.Forms.TextBox
$ADOUTxt.Location = New-Object System.Drawing.Size(10,20)
$ADOUTxt.Size =New-Object System.Drawing.Size(310,22)
$ADOUTxt.ReadOnly = $true
$ADOUTxt.Text = ""
$GroupBoxUserOU.Controls.Add($ADOUTxt)

# Benutzer Status Symbol
$StatusBox = new-object System.Windows.Forms.CheckBox 
$StatusBox.Location = new-object System.Drawing.Point(10,50)
$StatusBox.Size = new-object System.Drawing.Size(300,20)
$StatusBox.Text = "Benutzer aktiviert"
$StatusBox.Enabled = $false
$GroupBoxUserOU.Controls.Add($StatusBox)


# AD-Profil Text Anzeigen lassen
# AD-Profil erstellen Text Anzeigen lassen
$ADProfilCreateTXT1 = New-Object System.Windows.Forms.Label
$ADProfilCreateTXT1.Location = New-Object System.Drawing.Size(10,25)
$ADProfilCreateTXT1.Size =New-Object System.Drawing.Size(120,22)
$ADProfilCreateTXT1.Text = "AD Anmeldeskript:"# Verbinden von mit Pfad"
$GroupBoxADProfil.Controls.Add($ADProfilCreateTXT1)

$txtBoxADSkriptCreate = New-Object System.Windows.Forms.Textbox
$txtBoxADSkriptCreate.Location = New-Object System.Drawing.Size(130,22)
$txtBoxADSkriptCreate.Size = New-Object System.Drawing.Size(150,15)
$txtBoxADSkriptCreate.Text = "'AD Anmeldeskript'"
$txtBoxADSkriptCreate.ReadOnly = $false
$txtBoxADSkriptCreate.TabIndex = 1
$GroupBoxADProfil.Controls.ADD($txtBoxADSkriptCreate)

# AD-Profil erstellen Text Anzeigen lassen
$ADProfilCreateTXT2 = New-Object System.Windows.Forms.Label
$ADProfilCreateTXT2.Location = New-Object System.Drawing.Size(290,25)
$ADProfilCreateTXT2.Size =New-Object System.Drawing.Size(100,22)
$ADProfilCreateTXT2.Text = "Verbinden von" #mit Pfad"
$GroupBoxADProfil.Controls.Add($ADProfilCreateTXT2)

$txtBoxADDriveLetterCreate = New-Object System.Windows.Forms.Textbox
$txtBoxADDriveLetterCreate.Location = New-Object System.Drawing.Size(390,22)
$txtBoxADDriveLetterCreate.Size = New-Object System.Drawing.Size(50,15)
$txtBoxADDriveLetterCreate.Text = "'?:'"
$txtBoxADDriveLetterCreate.ReadOnly = $false
$txtBoxADDriveLetterCreate.TabIndex = 1
$GroupBoxADProfil.Controls.ADD($txtBoxADDriveLetterCreate)

# AD-Profil erstellen Text Anzeigen lassen
$ADProfilCreateTXT3 = New-Object System.Windows.Forms.Label
$ADProfilCreateTXT3.Location = New-Object System.Drawing.Size(450,25)
$ADProfilCreateTXT3.Size =New-Object System.Drawing.Size(30,22)
$ADProfilCreateTXT3.Text = "mit:" #mit Pfad"
$GroupBoxADProfil.Controls.Add($ADProfilCreateTXT3)

$txtBoxADPathCreate = New-Object System.Windows.Forms.Textbox
$txtBoxADPathCreate.Location = New-Object System.Drawing.Size(490,22)
$txtBoxADPathCreate.Size = New-Object System.Drawing.Size(200,15)
$txtBoxADPathCreate.Text = "'Profilpfad'"
$txtBoxADPathCreate.ReadOnly = $false
$txtBoxADPathCreate.TabIndex = 1
$GroupBoxADProfil.Controls.ADD($txtBoxADPathCreate)

# TS-Profil erstellen Text Anzeigen lassen
$TSProfilCreateTXT1 = New-Object System.Windows.Forms.Label
$TSProfilCreateTXT1.Location = New-Object System.Drawing.Size(10,25)
$TSProfilCreateTXT1.Size =New-Object System.Drawing.Size(70,22)
$TSProfilCreateTXT1.Text = "Profilpfad"# Verbinden von mit Pfad"
$GroupBoxTSProfil.Controls.Add($TSProfilCreateTXT1)

$txtBoxTSSkriptCreate = New-Object System.Windows.Forms.Textbox
$txtBoxTSSkriptCreate.Location = New-Object System.Drawing.Size(80,22)
$txtBoxTSSkriptCreate.Size = New-Object System.Drawing.Size(180,15)
$txtBoxTSSkriptCreate.Text = "'Terminalservice Skript'"
$txtBoxTSSkriptCreate.ReadOnly = $false
$txtBoxTSSkriptCreate.TabIndex = 1
$GroupBoxTSProfil.Controls.ADD($txtBoxTSSkriptCreate)

# TS-Profil erstellen Text Anzeigen lassen
$TSProfilCreateTXT2 = New-Object System.Windows.Forms.Label
$TSProfilCreateTXT2.Location = New-Object System.Drawing.Size(270,25)
$TSProfilCreateTXT2.Size =New-Object System.Drawing.Size(100,22)
$TSProfilCreateTXT2.Text = "Verbinden von" #mit Pfad"
$GroupBoxTSProfil.Controls.Add($TSProfilCreateTXT2)

$txtBoxTSDriveLetterCreate = New-Object System.Windows.Forms.Textbox
$txtBoxTSDriveLetterCreate.Location = New-Object System.Drawing.Size(370,22)
$txtBoxTSDriveLetterCreate.Size = New-Object System.Drawing.Size(50,15)
$txtBoxTSDriveLetterCreate.Text = "'?:'"
$txtBoxTSDriveLetterCreate.ReadOnly = $false
$txtBoxTSDriveLetterCreate.TabIndex = 1
$GroupBoxTSProfil.Controls.ADD($txtBoxTSDriveLetterCreate)

# TS-Profil erstellen Text Anzeigen lassen
$TSProfilCreateTXT3 = New-Object System.Windows.Forms.Label
$TSProfilCreateTXT3.Location = New-Object System.Drawing.Size(430,25)
$TSProfilCreateTXT3.Size =New-Object System.Drawing.Size(30,22)
$TSProfilCreateTXT3.Text = "mit:" #mit Pfad"
$GroupBoxTSProfil.Controls.Add($TSProfilCreateTXT3)

$txtBoxTSPathCreate = New-Object System.Windows.Forms.Textbox
$txtBoxTSPathCreate.Location = New-Object System.Drawing.Size(470,22)
$txtBoxTSPathCreate.Size = New-Object System.Drawing.Size(200,15)
$txtBoxTSPathCreate.Text = "'Profilpfad'"
$txtBoxTSPathCreate.ReadOnly = $false
$txtBoxTSPathCreate.TabIndex = 1
$GroupBoxTSProfil.Controls.ADD($txtBoxTSPathCreate)

#Exchange mailbox anlegen? Erstmal Settings INI überprüfen
$CHKBoxExchangeMailbox = New-Object System.Windows.Forms.CheckBox
$CHKBoxExchangeCheckedSettings =  if ($LoadExchangeCMDLets -eq "Ja"){ $CHKBoxExchangeMailbox.Enabled =$true} else { $CHKBoxExchangeMailbox.Enabled = $false}
$CHKBoxExchangeMailbox.Location = New-Object System.Drawing.Size(10,25)
$CHKBoxExchangeMailbox.Size = New-Object System.Drawing.Size(200,20)
$CHKBoxExchangeMailbox.Text = "Exchange Mailbox anlegen?"
$CHKBoxExchangeMailbox.TabIndex = 1
$CHKBoxExchangeMailbox.add_Click($ExchangeHandler)
$GroupBoxExchange.Controls.ADD($CHKBoxExchangeMailbox)

#Exchange Datenbank definieren oder automatsich auswählen
$DatabaseAutoSelect = New-Object System.Windows.Forms.RadioButton
$DatabaseManualSelect = New-Object System.Windows.Forms.RadioButton

$DatabaseAutoSelect.Location = New-Object System.Drawing.Size(10,50)
$DatabaseAutoSelect.Size = New-Object System.Drawing.Size(300,20)
$DatabaseAutoSelect.Text = "Datenbank automatsich auswählen"
$DatabaseAutoSelect.TabIndex = 8
$DatabaseAutoSelect.Enabled = $false
$DatabaseAutoSelect.add_Click($DabaseSelectHandler)
$GroupBoxExchange.Controls.Add($DatabaseAutoSelect)


$DatabaseManualSelect.Location = New-Object System.Drawing.Size(10,75)
$DatabaseManualSelect.Size = New-Object System.Drawing.Size(300,20)
$DatabaseManualSelect.Text = "Datenbank manuell auswählen"
$DatabaseManualSelect.TabIndex = 9
$DatabaseManualSelect.Enabled = $false
$DatabaseManualSelect.add_Click($DabaseSelectHandler)
$GroupBoxExchange.Controls.Add($DatabaseManualSelect)

#Exchange Benutzerdefinierte Attribute verwenden
$ADExtensioAttributes = New-Object System.Windows.Forms.Label
$ADExtensioAttributes.Location = New-Object System.Drawing.Size(10,303)
$ADExtensioAttributes.Size =New-Object System.Drawing.Size(140,50)
$ADExtensioAttributes.Text = "ExtensionAttribut1

ExtensionAttribut2
"
$ADExtensioAttributes.Enabled = $false
#$ADExtensioAttributes.Visible = $false
$GroupBoxExchange.Controls.Add($ADExtensioAttributes)


#Auswahlfeld der Datenbanken anzeigen wenn DBs manuell ausgewählt wurde
$DatabaseName = New-Object System.Windows.Forms.Combobox
$DatabaseName.Location = New-Object System.Drawing.Size(25,100)
$DatabaseName.Size = New-Object System.Drawing.Size(250,15)
$DatabaseName.TabIndex = 4
$DatabaseName.AutoCompleteMode = 3
$DatabaseName.AutoCompleteSource = 256
$DatabaseName.DataBindings.DefaultDataSourceUpdateMode = 0
$DatabaseName.FormattingEnabled = $True
$DatabaseName.Enabled = $False
$GroupBoxExchange.Controls.Add($DatabaseName)

#Checkbox für beabreiten der rollenzuweisungsrichtlinin
$CHKBoxrolePolicy = New-Object System.Windows.Forms.CheckBox
$CHKBoxrolePolicy.Enabled = $false
$CHKBoxrolePolicy.Location = New-Object System.Drawing.Size(10,130)
$CHKBoxrolePolicy.Size = New-Object System.Drawing.Size(280,20)
$CHKBoxrolePolicy.Text = "Rollezuweisungsrichtlinie auswählen?"
$CHKBoxrolePolicy.TabIndex = 1
$CHKBoxrolePolicy.add_Click($RolePolicyHandler)
$GroupBoxExchange.Controls.ADD($CHKBoxrolePolicy)
 
#Auswahlfeld der Rollezuweisungsrichtlinien
$RolePolicy = New-Object System.Windows.Forms.Combobox
$RolePolicy.Location = New-Object System.Drawing.Size(25,155)
$RolePolicy.Size = New-Object System.Drawing.Size(250,15)
$RolePolicy.TabIndex = 4
$RolePolicy.AutoCompleteMode = 3
$RolePolicy.AutoCompleteSource = 256
$RolePolicy.DataBindings.DefaultDataSourceUpdateMode = 0
$RolePolicy.FormattingEnabled = $True
$RolePolicy.Enabled = $False
$GroupBoxExchange.Controls.Add($RolePolicy)

#Checkbox für beabreiten der rollenzuweisungsrichtlinin
$CHKBoxEASPolicy = New-Object System.Windows.Forms.CheckBox
$CHKBoxEASPolicy.Enabled = $false
$CHKBoxEASPolicy.Location = New-Object System.Drawing.Size(10,185)
$CHKBoxEASPolicy.Size = New-Object System.Drawing.Size(280,20)
$CHKBoxEASPolicy.Text = "ActiveSync Richtlinie auswählen?"
$CHKBoxEASPolicy.TabIndex = 1
$CHKBoxEASPolicy.add_Click($EASPolicyHandler)
$GroupBoxExchange.Controls.ADD($CHKBoxEASPolicy)

#Auswahlfeld der ActiveSync Richtlinien
$EASPolicy = New-Object System.Windows.Forms.Combobox
$EASPolicy.Location = New-Object System.Drawing.Size(25,210)
$EASPolicy.Size = New-Object System.Drawing.Size(250,15)
$EASPolicy.TabIndex = 4
$EASPolicy.AutoCompleteMode = 3
$EASPolicy.AutoCompleteSource = 256
$EASPolicy.DataBindings.DefaultDataSourceUpdateMode = 0
$EASPolicy.FormattingEnabled = $True
$EASPolicy.Enabled = $False
$GroupBoxExchange.Controls.Add($EASPolicy)

#Checkbox für beabreiten der Adressbuchrichtlinien
$CHKBoxABPolicy = New-Object System.Windows.Forms.CheckBox
$CHKBoxABPolicy.Enabled = $false
$CHKBoxABPolicy.Location = New-Object System.Drawing.Size(10,240)
$CHKBoxABPolicy.Size = New-Object System.Drawing.Size(280,20)
$CHKBoxABPolicy.Text = "Adressbuch-Richtlinie auswählen?"
$CHKBoxABPolicy.TabIndex = 1
$CHKBoxABPolicy.add_Click($ABPolicyHandler)
$GroupBoxExchange.Controls.ADD($CHKBoxABPolicy)

#Auswahlfeld der Adressbuchrichtlinien
$ABPolicy = New-Object System.Windows.Forms.Combobox
$ABPolicy.Location = New-Object System.Drawing.Size(25,265)
$ABPolicy.Size = New-Object System.Drawing.Size(250,15)
$ABPolicy.TabIndex = 4
$ABPolicy.AutoCompleteMode = 3
$ABPolicy.AutoCompleteSource = 256
$ABPolicy.DataBindings.DefaultDataSourceUpdateMode = 0
$ABPolicy.FormattingEnabled = $True
$ABPolicy.Enabled = $False
$GroupBoxExchange.Controls.Add($ABPolicy)


#Textboxen für ADExtAttributCreate
$txtBoxAdExt1Create = New-Object System.Windows.Forms.Textbox
$txtBoxAdExt1Create.Location = New-Object System.Drawing.Size(150,300)
$txtBoxAdExt1Create.Size = New-Object System.Drawing.Size(180,15)
$txtBoxAdExt1Create.Text = "'ExtensionAttribute 1'"
$txtBoxAdExt1Create.Enabled = $false
$txtBoxAdExt1Create.TabIndex = 1
$GroupBoxExchange.Controls.Add($txtBoxAdExt1Create)

$txtBoxAdExt2Create = New-Object System.Windows.Forms.Textbox
$txtBoxAdExt2Create.Location = New-Object System.Drawing.Size(150,333)
$txtBoxAdExt2Create.Size = New-Object System.Drawing.Size(180,15)
$txtBoxAdExt2Create.Text = "'ExtensionAttribute 2'"
$txtBoxAdExt2Create.Enabled = $false
$txtBoxAdExt2Create.TabIndex = 1
$GroupBoxExchange.Controls.Add($txtBoxAdExt2Create)



#Datenübernahmen von Referenz Benutzer Button
$UserDatenGet = New-Object System.Windows.Forms.Button
$UserDatenGet.Location = New-Object System.Drawing.Size(750,18)
$UserDatenGet.Size = New-Object System.Drawing.Size(350,50)
$UserDatenGet.Text = "Daten von Referenz Benutzer übernehmen"
$UserDatenGet.TabIndex = 18
$UserDatenGet.BackColor = "white"
$UserDatenGet.Add_Click({Referenz})
$TabUserCreate.Controls.Add($UserDatenGet)



#Speicherbutton für benutzer anlegen
$SpeichernCreate = New-Object System.Windows.Forms.Button
$SpeichernCreate.Location = New-Object System.Drawing.Size(750,618)
$SpeichernCreate.Size = New-Object System.Drawing.Size(350,60)
$SpeichernCreate.Text = "Benutzer anlegen"
$SpeichernCreate.TabIndex = 18
$SpeichernCreate.BackColor = "white"
$SpeichernCreate.Add_Click({NeuerBenutzer})
$TabUserCreate.Controls.Add($SpeichernCreate)

# Benutzermailbox auflösen
$UsernameAbfragen = New-Object System.Windows.Forms.Button
$UsernameAbfragen.Location = New-Object System.Drawing.Size(240,20)
$UsernameAbfragen.Size = New-Object System.Drawing.Size(80,22)
$UsernameAbfragen.Text = "Abfragen"
$UsernameAbfragen.TabIndex = 5
$UsernameAbfragen.BackColor = "white"
$UsernameAbfragen.Add_Click({Abfrage;BearbeitungDeaktivieren;FelderReset})
$GroupBoxUser.Controls.Add($UsernameAbfragen)

# Stammdaten Text Anzeigen lassen
$Stammdaten = New-Object System.Windows.Forms.Label
$Stammdaten.Location = New-Object System.Drawing.Size(10,25)
$Stammdaten.Size =New-Object System.Drawing.Size(150,167)
$Stammdaten.Text = "GID

Nachname

Vorname

samAccountName

eMail-Adresse

Exchange-Alias"
$GroupBoxUserData1.Controls.Add($Stammdaten)

#EmployeeID
$txtBoxEmployeeID = New-Object System.Windows.Forms.Textbox
$txtBoxEmployeeID.Location = New-Object System.Drawing.Size(160,22)
$txtBoxEmployeeID.Size = New-Object System.Drawing.Size(180,15)
$txtBoxEmployeeID.Text = "'GID'"
$txtBoxEmployeeID.ReadOnly = $true
$txtBoxEmployeeID.TabIndex = 1
$GroupBoxUserData1.Controls.Add($txtBoxEmployeeID)

$txtBoxNachname = New-Object System.Windows.Forms.Textbox
$txtBoxNachname.Location = New-Object System.Drawing.Size(160,52)
$txtBoxNachname.Size = New-Object System.Drawing.Size(180,15)
$txtBoxNachname.Text = "'Nachname'"
$txtBoxNachname.ReadOnly = $true
$txtBoxNachname.TabIndex = 1
$GroupBoxUserData1.Controls.Add($txtBoxNachname)

$txtBoxVorname = New-Object System.Windows.Forms.Textbox
$txtBoxVorname.Location = New-Object System.Drawing.Size(160,82)
$txtBoxVorname.Size = New-Object System.Drawing.Size(180,15)
$txtBoxVorname.Text = "'Vorname'"
$txtBoxVorname.ReadOnly = $true
$txtBoxVorname.TabIndex = 1
$GroupBoxUserData1.Controls.Add($txtBoxVorname)

$txtBoxSam = New-Object System.Windows.Forms.Textbox
$txtBoxSam.Location = New-Object System.Drawing.Size(160,112)
$txtBoxSam.Size = New-Object System.Drawing.Size(180,15)
$txtBoxSam.Text = "'SamAccountName'"
$txtBoxSam.ReadOnly = $true
$txtBoxSam.TabIndex = 1
$GroupBoxUserData1.Controls.Add($txtBoxSam)

$txtBoxMail = New-Object System.Windows.Forms.Textbox
$txtBoxMail.Location = New-Object System.Drawing.Size(160,142)
$txtBoxMail.Size = New-Object System.Drawing.Size(180,15)
$txtBoxMail.Text = "'Mail'"
$txtBoxMail.ReadOnly = $true
$txtBoxMail.TabIndex = 1
$GroupBoxUserData1.Controls.Add($txtBoxMail)

$txtBoxAlias = New-Object System.Windows.Forms.Textbox
$txtBoxAlias.Location = New-Object System.Drawing.Size(160,172)
$txtBoxAlias.Size = New-Object System.Drawing.Size(180,15)
$txtBoxAlias.Text = "'Exchange-Alias'"
$txtBoxAlias.ReadOnly = $true
$txtBoxAlias.TabIndex = 1
$GroupBoxUserData1.Controls.Add($txtBoxAlias)

# Organisationsdaten Text Anzeigen lassen
$Orgdaten = New-Object System.Windows.Forms.Label
$Orgdaten.Location = New-Object System.Drawing.Size(10,25)
$Orgdaten.Size =New-Object System.Drawing.Size(150,270)
$Orgdaten.Text = "Beschreibung

Büro

Rufnummer

Mobil

Fax

Position

Abteilung

Firma

Kostenstelle"
$GroupBoxUserData2.Controls.Add($Orgdaten)


$txtBoxBeschreibung = New-Object System.Windows.Forms.Textbox
$txtBoxBeschreibung.Location = New-Object System.Drawing.Size(160,22)
$txtBoxBeschreibung.Size = New-Object System.Drawing.Size(180,15)
$txtBoxBeschreibung.Text = "'Beschreibung'"
$txtBoxBeschreibung.ReadOnly = $true
$txtBoxBeschreibung.TabIndex = 1
$GroupBoxUserData2.Controls.Add($txtBoxBeschreibung)

$txtBoxOffice = New-Object System.Windows.Forms.Textbox
$txtBoxOffice.Location = New-Object System.Drawing.Size(160,52)
$txtBoxOffice.Size = New-Object System.Drawing.Size(180,15)
$txtBoxOffice.Text = "'Büro'"
$txtBoxOffice.ReadOnly = $true
$txtBoxOffice.TabIndex = 1
$GroupBoxUserData2.Controls.Add($txtBoxOffice)

$txtBoxPhone = New-Object System.Windows.Forms.Textbox
$txtBoxPhone.Location = New-Object System.Drawing.Size(160,82)
$txtBoxPhone.Size = New-Object System.Drawing.Size(180,15)
$txtBoxPhone.Text = "'Telefon'"
$txtBoxPhone.ReadOnly = $true
$txtBoxPhone.TabIndex = 1
$GroupBoxUserData2.Controls.Add($txtBoxPhone)

$txtBoxMobil = New-Object System.Windows.Forms.Textbox
$txtBoxMobil.Location = New-Object System.Drawing.Size(160,112)
$txtBoxMobil.Size = New-Object System.Drawing.Size(180,15)
$txtBoxMobil.Text = "'Mobilfunk'"
$txtBoxMobil.ReadOnly = $true
$txtBoxMobil.TabIndex = 1
$GroupBoxUserData2.Controls.Add($txtBoxMobil)

$txtBoxFax = New-Object System.Windows.Forms.Textbox
$txtBoxFax.Location = New-Object System.Drawing.Size(160,142)
$txtBoxFax.Size = New-Object System.Drawing.Size(180,15)
$txtBoxFax.Text = "'Fax'"
$txtBoxFax.ReadOnly = $true
$txtBoxFax.TabIndex = 1
$GroupBoxUserData2.Controls.Add($txtBoxFax)

$txtBoxPosition = New-Object System.Windows.Forms.Textbox
$txtBoxPosition.Location = New-Object System.Drawing.Size(160,172)
$txtBoxPosition.Size = New-Object System.Drawing.Size(180,15)
$txtBoxPosition.Text = "'Position'"
$txtBoxPosition.ReadOnly = $true
$txtBoxPosition.TabIndex = 1
$GroupBoxUserData2.Controls.Add($txtBoxPosition)

$txtBoxAbteilung = New-Object System.Windows.Forms.Textbox
$txtBoxAbteilung.Location = New-Object System.Drawing.Size(160,202)
$txtBoxAbteilung.Size = New-Object System.Drawing.Size(180,15)
$txtBoxAbteilung.Text = "'Abteilung'"
$txtBoxAbteilung.ReadOnly = $true
$txtBoxAbteilung.TabIndex = 1
$GroupBoxUserData2.Controls.Add($txtBoxAbteilung)

$txtBoxFirma = New-Object System.Windows.Forms.Textbox
$txtBoxFirma.Location = New-Object System.Drawing.Size(160,232)
$txtBoxFirma.Size = New-Object System.Drawing.Size(180,15)
$txtBoxFirma.Text = "'Firma'"
$txtBoxFirma.ReadOnly = $true
$txtBoxFirma.TabIndex = 1
$GroupBoxUserData2.Controls.Add($txtBoxFirma)

$txtBoxEmployeeNr = New-Object System.Windows.Forms.Textbox
$txtBoxEmployeeNr.Location = New-Object System.Drawing.Size(160,262)
$txtBoxEmployeeNr.Size = New-Object System.Drawing.Size(180,15)
$txtBoxEmployeeNr.Text = "'Kostenstelle'"
$txtBoxEmployeeNr.ReadOnly = $true
$txtBoxEmployeeNr.TabIndex = 1
$GroupBoxUserData2.Controls.Add($txtBoxEmployeeNr)

#chekcbox für TFP oder auch Benutzerdefiniertes Attribut 15 wenn wert =1 dann Check, wenn Wert = 0 dann uncheck
$CHKBoxADExt15 = new-object System.Windows.Forms.CheckBox 
$CHKBoxADExt15.Location = new-object System.Drawing.Point(10,295)
$CHKBoxADExt15.Size = new-object System.Drawing.Size(300,20)
$CHKBoxADExt15.Text = "$AdExt15"
$CHKBoxADExt15.Enabled = $false
#$CHKBoxADExt15.add_Click($handlerPWDChange)
$GroupBoxUserData2.Controls.Add($CHKBoxADExt15)

#Kennwortänderungen hierhin...
$PWDChange = new-object System.Windows.Forms.CheckBox 
$PWDChange.Location = new-object System.Drawing.Point(10,30)
$PWDChange.Size = new-object System.Drawing.Size(300,20)
$PWDChange.Text = "Das Kennwort soll geändert werden!"
$PWDChange.Enabled = $false
$PWDChange.add_Click($handlerPWDChange)
$GroupBoxUserPWDChange.Controls.Add($PWDChange)

$txtBoxPWDChange = New-Object System.Windows.Forms.Textbox
$txtBoxPWDChange.Location = New-Object System.Drawing.Size(10,60)
$txtBoxPWDChange.Size = New-Object System.Drawing.Size(180,15)
$txtBoxPWDChange.Text = "'Neues Kennwort'"
$txtBoxPWDChange.ReadOnly = $true
$txtBoxPWDChange.TabIndex = 1
$GroupBoxUserPWDChange.Controls.Add($txtBoxPWDChange)

$PWDChangeNextLogon = new-object System.Windows.Forms.CheckBox 
$PWDChangeNextLogon.Location = new-object System.Drawing.Point(10,100)
$PWDChangeNextLogon.Size = new-object System.Drawing.Size(300,40)
$PWDChangeNextLogon.Text = "Benutzer muss Kennwort bei der nächsten Anmledung ändern"
$PWDChangeNextLogon.Enabled = $false
$GroupBoxUserPWDChange.Controls.Add($PWDChangeNextLogon)


# AD-Profil Text Anzeigen lassen
$ADProfil = New-Object System.Windows.Forms.Label
$ADProfil.Location = New-Object System.Drawing.Size(10,25)
$ADProfil.Size =New-Object System.Drawing.Size(150,140)
$ADProfil.Text = "Anmeldeskript

Verbinden von

mit Pfad

ExtensionAttribut1

ExtensionAttribut2
"

$GroupBoxUserData3.Controls.Add($ADProfil)

$txtBoxADSkript = New-Object System.Windows.Forms.Textbox
$txtBoxADSkript.Location = New-Object System.Drawing.Size(160,22)
$txtBoxADSkript.Size = New-Object System.Drawing.Size(180,15)
$txtBoxADSkript.Text = "'AD Anmeldeskript'"
$txtBoxADSkript.ReadOnly = $true
$txtBoxADSkript.TabIndex = 1
$GroupBoxUserData3.Controls.Add($txtBoxADSkript)

$txtBoxADDriveLetter = New-Object System.Windows.Forms.Textbox
$txtBoxADDriveLetter.Location = New-Object System.Drawing.Size(160,52)
$txtBoxADDriveLetter.Size = New-Object System.Drawing.Size(50,15)
$txtBoxADDriveLetter.Text = "'?:\'"
$txtBoxADDriveLetter.ReadOnly = $true
$txtBoxADDriveLetter.TabIndex = 1
$GroupBoxUserData3.Controls.Add($txtBoxADDriveLetter)

$txtBoxADPath = New-Object System.Windows.Forms.Textbox
$txtBoxADPath.Location = New-Object System.Drawing.Size(160,84)
$txtBoxADPath.Size = New-Object System.Drawing.Size(180,15)
$txtBoxADPath.Text = "'Pfad'"
$txtBoxADPath.ReadOnly = $true
$txtBoxADPath.TabIndex = 1
$GroupBoxUserData3.Controls.Add($txtBoxADPath)

$txtBoxAdExt1 = New-Object System.Windows.Forms.Textbox
$txtBoxAdExt1.Location = New-Object System.Drawing.Size(160,116)
$txtBoxAdExt1.Size = New-Object System.Drawing.Size(180,15)
$txtBoxAdExt1.Text = "'ExtensionAttribute 1'"
$txtBoxAdExt1.ReadOnly = $true
$txtBoxAdExt1.TabIndex = 1
$GroupBoxUserData3.Controls.Add($txtBoxAdExt1)

$txtBoxAdExt2 = New-Object System.Windows.Forms.Textbox
$txtBoxAdExt2.Location = New-Object System.Drawing.Size(160,148)
$txtBoxAdExt2.Size = New-Object System.Drawing.Size(180,15)
$txtBoxAdExt2.Text = "'ExtensionAttribute 2'"
$txtBoxAdExt2.ReadOnly = $true
$txtBoxAdExt2.TabIndex = 1
$GroupBoxUserData3.Controls.Add($txtBoxAdExt2)

# TS-Profil Text Anzeigen lassen
$TSProfil = New-Object System.Windows.Forms.Label
$TSProfil.Location = New-Object System.Drawing.Size(10,25)
$TSProfil.Size =New-Object System.Drawing.Size(150,140)
$TSProfil.Text = "Profilpfad

Verbinden von

mit Pfad"

$GroupBoxUserData4.Controls.Add($TSProfil)

$txtBoxTSSkript = New-Object System.Windows.Forms.Textbox
$txtBoxTSSkript.Location = New-Object System.Drawing.Size(160,22)
$txtBoxTSSkript.Size = New-Object System.Drawing.Size(180,15)
$txtBoxTSSkript.Text = "'Terminalservice Skript'"
$txtBoxTSSkript.ReadOnly = $true
$txtBoxTSSkript.TabIndex = 1
$GroupBoxUserData4.Controls.ADD($txtBoxTSSkript)

$txtBoxTSDriveLetter = New-Object System.Windows.Forms.Textbox
$txtBoxTSDriveLetter.Location = New-Object System.Drawing.Size(160,52)
$txtBoxTSDriveLetter.Size = New-Object System.Drawing.Size(50,15)
$txtBoxTSDriveLetter.Text = "'?:\'"
$txtBoxTSDriveLetter.ReadOnly = $true
$txtBoxTSDriveLetter.TabIndex = 1
$GroupBoxUserData4.Controls.ADD($txtBoxTSDriveLetter)

$txtBoxTSPath = New-Object System.Windows.Forms.Textbox
$txtBoxTSPath.Location = New-Object System.Drawing.Size(160,84)
$txtBoxTSPath.Size = New-Object System.Drawing.Size(180,15)
$txtBoxTSPath.Text = "'Profilpfad'"
$txtBoxTSPath.ReadOnly = $true
$txtBoxTSPath.TabIndex = 1
$GroupBoxUserData4.Controls.ADD($txtBoxTSPath)

#Datenfreigabe button
$ChangeDataButton1 = New-Object System.Windows.Forms.Button
$ChangeDataButton1.Location = New-Object System.Drawing.Size(190,30)
$ChangeDataButton1.Size = New-Object System.Drawing.Size(150,22)
$ChangeDataButton1.Text = "Bearbeitung aktivieren"
$ChangeDataButton1.TabIndex = 18
$ChangeDataButton1.BackColor = "white"
$ChangeDataButton1.Add_Click({BearbeitungAktivieren})
$GroupBoxBearbeitung.Controls.Add($ChangeDataButton1) 

#Datenfreigabe button
$ChangeDataButton2 = New-Object System.Windows.Forms.Button
$ChangeDataButton2.Location = New-Object System.Drawing.Size(10,30)
$ChangeDataButton2.Size = New-Object System.Drawing.Size(170,22)
$ChangeDataButton2.Text = "Bearbeitung deaktivieren"
$ChangeDataButton2.TabIndex = 18
$ChangeDataButton2.BackColor = "white"
$ChangeDataButton2.Add_Click({BearbeitungDeaktivieren})
$GroupBoxBearbeitung.Controls.Add($ChangeDataButton2) 


# Speicherbutton bauen
$Speichern = New-Object System.Windows.Forms.Button
$Speichern.Location = New-Object System.Drawing.Size(150,30)
$Speichern.Size = New-Object System.Drawing.Size(170,22)
$Speichern.Text = "Speichern / aktualisieren"
$Speichern.TabIndex = 18
$Speichern.BackColor = "white"
$Speichern.Add_Click({Speichern;BearbeitungDeaktivieren})
$GroupBoxSpeichern.Controls.Add($Speichern)

#Forstschrittsanzeige speichern

$Fortschritt.Location = New-Object System.Drawing.Size(10,710)
$Fortschritt.Size = New-Object System.Drawing.Size(430,20)
$Fortschritt.Style = "Marquee"
$Fortschritt.Value = 100
$Fortschritt.ForeColor = "#B2E4FF"
$Fortschritt.BackColor = "#B2E4FF"
$Fortschritt.Visible = $false 
$Fortschritt.MarqueeAnimationSpeed = 30
$Fenster1.Controls.Add($Fortschritt)

# Fortschritt Text anzeigen lassen
$FortschrittText = New-Object System.Windows.Forms.Label
$FortschrittText.Location = New-Object System.Drawing.Size(445,712)
$FortschrittText.Size =New-Object System.Drawing.Size(150,140)
$FortschrittText.Text = ""
$Fenster1.Controls.Add($FortschrittText)

#Tabs erstellen

$Tabcontrol = New-Object System.Windows.Forms.TabControl
$Tabcontrol.Controls.Add($TabUserEdit)
$Tabcontrol.Controls.Add($TabUserCreate)
$Tabcontrol.Location = '0, 10'
$Tabcontrol.Name = "Tabcontrol"
$Tabcontrol.SelectedIndex = 0
$Tabcontrol.Size = "$WindowWidth, 695"
$Tabcontrol.TabIndex = 0
#$Tabcontrol.Appearance = "FlatButtons"
#$Tabcontrol.DrawMode = "OwnerDrawFixed"
$Tabcontrol.BackColor = "#B2E4FF"
#$Tabcontrol.ForeColor = "#B2E4FF"
$Fenster1.Controls.Add($Tabcontrol)

#$TabUserEdit = New-Object 'System.Windows.Forms.TabPage'
$TabUserEdit.Location = New-Object System.Drawing.Size(50,50)
$TabUserEdit.Size = New-Object System.Drawing.Size(100,100)
$TabUserEdit.Name ="Tab Benutzer bearbeiten"
$TabUserEdit.Text = "Benutzer bearbeiten (Referenz Benutzer)"
$TabUserEdit.TabIndex = 0
$TabUserEdit.UseVisualStyleBackColor = $true
$TabUserEdit.BackColor = "#B2E4FF"
#$TabUserEdit.ForeColor = "Transparent"
$TabUserEdit.BorderStyle = "none"

#$TabUserCreate = New-Object 'System.Windows.Forms.TabPage'
$TabUserCreate.Location = New-Object System.Drawing.Size(50,50)
$TabUserCreate.Size = New-Object System.Drawing.Size(100,100)
$TabUserCreate.Name ="Tab Benutzer erstellen"
$TabUserCreate.Text = "Benutzer erstellen (aus Referenz Benutzer)"
$TabUserCreate.TabIndex = 1
$TabUserCreate.UseVisualStyleBackColor = $true
$TabUserCreate.BackColor = "#B2E4FF"
#$TabUserCreate.ForeColor = "Transparent"
$TabUserCreate.BorderStyle = "none"

# Fenster anzeigen lassen
[System.Windows.Forms.Application]::EnableVisualStyles();
[System.Windows.Forms.Application]::DoEvents();
[System.Windows.Forms.Application]::Run($Fenster1)#,($Fortschritt)
$Fenster1.Add_Shown({$Fenster1.Activate()});
$notifyIcon.Dispose();
#[System.Windows.Forms.Application]::Run($Fortschritt)
#[void] $Fenster1.ShowDialog()