Untitled

mail@pastecode.io avatar
unknown
powershell
2 years ago
50 kB
1
Indexable
Never
#region functies aanmaken gebruiker en benodigdheden

Function Check-IfUserExists {
    Param([ValidateSet('All', 'samAccountName', 'UserPrincipalName', 'mail', 'Displayname')]$check)
    $conflict = $false
    
    If ($check -match 'All|samAccountName') {
        $user = Get-ADUser -Filter ('samAccountName -eq "{0}"' -f $window.tbPrewin.Text)
        If ($user) {
            $prompt = ('Een gebruiker met samAccountName {0} bestaat al' -f $window.tbPrewin.Text)
            Show-MsgBox -Prompt $prompt -Title 'CONFLICT' -Icon Exclamation -BoxType OKOnly
            $window.tbPrewin.Foreground = '#FFFF0000'
            $conflict = $true
        } Else { $window.tbPrewin.Foreground = '#FF000000' }
    }

    If ($check -match 'All|UserPrincipalName') {
        $user = Get-ADUser -Filter ('UserPrincipalName -eq "{0}"' -f $window.tbUserlogon.Text)
        If ($user) {
            $prompt = ('Een gebruiker met UserPrincipalName {0} bestaat al' -f $window.tbUserlogon.Text)
            Show-MsgBox -Prompt $prompt -Title 'CONFLICT' -Icon Exclamation -BoxType OKOnly
            $window.tbUserlogon.Foreground = '#FFFF0000'
            $conflict = $true
        } Else { $window.tbUserlogon.Foreground = '#FF000000' }
    }
    
    If ($check -match 'All|mail' -and $window.cbExchange.IsChecked) {
        $user = Get-ADUser -Filter ('mail -eq "{0}"' -f $window.tbemail.Text)
        If ($user) {
            $prompt = ('Een gebruiker met email adres {0} bestaat al' -f $window.tbemail.Text)
            Show-MsgBox -Prompt $prompt -Title 'CONFLICT' -Icon Exclamation -BoxType OKOnly
            $window.tbemail.Foreground = '#FFFF0000'
            $conflict = $true
        } Else { $window.tbemail.Foreground = '#FF000000' }
    }

    If ($check -match 'All|Displayname') {
        $user = Get-ADUser -Filter ('Displayname -eq "{0}"' -f $window.tbDisplayname.Text)
        If ($user) {
            $prompt = ('Een gebruiker met Displayname {0} bestaat al. Zet de initialen in de displayname.' -f $window.tbDisplayname.Text)
            Show-MsgBox -Prompt $prompt -Title 'CONFLICT' -Icon Exclamation -BoxType OKOnly
            $window.tbDisplayname.IsReadOnly = $false
            $window.tbDisplayname.Background = '#FFFFFFFF'
            $window.tbDisplayname.Foreground = '#FFFF0000'
        } Else { $window.tbDisplayname.Foreground = '#FF000000' }
    }
    
    $conflict
}

Function Create-ADUser {
    $secPwd = ConvertTo-SecureString $window.tbWachtwoord.Text -AsPlainText -Force
    If ($window.cbHomeDir.IsChecked) { 
        $params = @{
            GivenName = $window.tbFirstname.Text
            Initials = $window.tbInitials.Text
            Surname = $window.tbLastname.Text
            DisplayName = $window.tbDisplayname.Text
            Name = $window.tbDisplayname.Text
            Description = $window.tbDescription.Text
            SamAccountName = $window.tbPrewin.Text
            UserPrincipalName = $window.tbUserlogon.Text
            AccountPassword = $secPwd
            ChangePasswordAtLogon = $true
            HomeDirectory = $window.tbhomeDir.Text
            HomeDrive = 'L:'
            City = 'Maastricht'
            Country = 'NL'
            Company = $script:persoon.WERKGEVER
            Path = $script:orgs.$script:Template.OU
        }
    } Else {
        $params = @{
            GivenName = $window.tbFirstname.Text
            Initials = $window.tbInitials.Text
            Surname = $window.tbLastname.Text
            DisplayName = $window.tbDisplayname.Text
            Name = $window.tbDisplayname.Text
            Description = $window.tbDescription.Text
            SamAccountName = $window.tbPrewin.Text
            UserPrincipalName = $window.tbUserlogon.Text
            AccountPassword = $secPwd
            ChangePasswordAtLogon = $true
            City = 'Maastricht'
            Country = 'NL'
            Company = $script:persoon.WERKGEVER
            Path = $script:orgs.$script:Template.OU
        }
    }

    New-ADUser @params
    
    Add-toLog -text 'De gebruiker is in AD aangemaakt.'
    
    If ($script:orgs.$script:Template.template) { 
        $groups = Get-ADUser -Identity $script:orgs.$script:Template.template -Properties memberof | Select-Object -ExpandProperty memberof
        $result = $groups | Add-ADGroupMember -Members $window.tbPrewin.Text
        Add-toLog ('Template: {0} toegepast.' -f $script:orgs.$script:Template.template)
    }
}

Function Create-UserMailbox {
    #Verbinden met Exchange
    $exchangeServer = 'http://spl3003.prvlimburg.nl/powershell'
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $exchangeServer
    Import-PSSession $session -AllowClobber -CommandName Get-Mailbox, Enable-Mailbox, Set-CASMailbox, Set-Mailbox

    $selectedDB = ($window.ddDB.SelectedValue.Content).Split(';')[0]

    Enable-Mailbox -Identity $window.tbPrewin.Text -Alias $window.tbPrewin.Text -Database $selectedDB -AddressBookPolicy $script:orgs.$script:template.ABP
    Set-Mailbox $window.tbPrewin.Text -EmailAddressPolicyEnabled $false #-AuditEnabled $true
    Set-CASMailbox -Identity $window.tbPrewin.Text -IMAPEnabled $false -POPEnabled $false -OwaMailboxPolicy 'Default' -OWAforDevicesEnabled $false

    #Instellen juiste mail adressen
    $mailBox = Get-Mailbox -identity $window.tbPrewin.Text
    $oldEmailAddressesWOprimary = $mailBox.EmailAddresses | Where { $_ -clike 'smtp*' }
    $oldEmailAddressesWprimary = ($mailBox.EmailAddresses | Where { $_ -like 'smtp*' }).ToLower()
    $mailUserPart = $window.tbemail.Text.split('@')[0]
    $newEmailAddresses = $oldEmailAddressesWOprimary | Foreach { $_ -replace($window.tbPrewin.Text, $mailUserPart) }

    Set-Mailbox -identity $window.tbPrewin.Text -PrimarySmtpAddress $window.tbemail.Text
    Set-Mailbox -identity $window.tbPrewin.Text -EmailAddresses @{add=$newEmailAddresses}
    Set-Mailbox -identity $window.tbPrewin.Text -EmailAddresses @{remove=$oldEmailAddressesWprimary}

    Remove-PSSession -Session $session
    Add-toLog -text 'Mailbox is aangemaakt.'
}

Function Create-HomeDir {
    $path = $window.tbhomeDir.Text
    $user = ('PRVLIMBURG.NL\{0}' -f $window.tbPrewin.Text)
    New-Item $path -ItemType Directory
    $Acl = (Get-Item $path).GetAccessControl('Access')
    $Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($user, "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
    $Acl.SetAccessRule($Ar)
    Set-Acl $path $Acl 
    Add-toLog -text 'Homedir is aangemaakt.'
}

#endregion functies aanmaken gebruiker en benodigdheden

#region algemene functies
Function Get-Persoon {
    $selectedValue = $script:window.ddPersnr.SelectedValue.Split(';')
    $myPersoon = $script:oraData | Where REGISTRATIE_NR -eq $selectedValue[0]
    $myPersoon
}
Function Copy-ToClipboard {
    $text = @'
Accountnaam: {0}
Email: {1}
Uit dienst per: {2}
K-schijf: 
Overige rechten:
AFAS aangepast: 
Skype aangemaakt: 
'@ -f $script:window.tbPrewin.Text, $script:window.tbemail.Text, $script:persoon.EINDDATUM_CONTRACT
    $text | clip
}
Function Get-Template {
    switch ($script:persoon.WERKGEVER) {
        'Provincie Limburg' { 
            $script:window.rbPRV.IsChecked = $true 
            If ($script:persoon.FUNC1 -like '*rekenkamer*') {
                $script:window.rbZRK.IsChecked = $true
                $myTemplate = 'ZRK'
                Add-toLog 'ZRK via concern. Als het account is aangemaakt, moet je in AD bij het email veld hun eigen mail adres zetten. Vermeld ook hun 06 nummer in het AD account.'
            } ElseIf ($script:persoon.ORG_OMS_WERKZ1 -eq 'Fractie') {
                $script:window.rbFM.IsChecked = $true
                $myTemplate = 'FM'
                Add-toLog 'Fractie medewerkers in overleg met Johan aanmaken!'
            } ElseIf ($script:persoon.ORG_OMS_WERKZ1 -eq 'Provinciale Staten' -or $script:persoon.ORG_OMS_WERKZ1 -eq 'Burgercommissieleden') {
                $script:window.rbSL.IsChecked = $true
                $myTemplate = 'SL'
                Add-toLog 'Statenleden en Burgercommissieleden in overleg met Johan aanmaken!'
            } ElseIf ($script:persoon.ORG_OMS_WERKZ1 -eq 'Schoonmaak') {
                $script:window.rbSM.IsChecked = $true
                $myTemplate = 'SM'
                Add-toLog 'Schoonmaak via facilitair'
            } ElseIf ($script:persoon.ORG_OMS_WERKZ1 -eq 'Catering') {
                $script:window.rbCAT.IsChecked = $true
                $myTemplate = 'CAT'
                Add-toLog 'Catering via facilitair'
            } Else { 
                $script:window.rbIntern.IsChecked = $true
                $myTemplate = 'PRV'
            }
        }
        'Regionale Uitvoeringsdienst Zuid-Limburg' { 
            $script:window.rbRUDZL.IsChecked = $true 
            $myTemplate = 'RUDZL'
        }
    }

    If ($myTemplate -match 'PRV|CAT|SM') {
        Hide-TemplatePRV -visibility visible
    } Else {
        Hide-TemplatePRV -visibility hidden
    }

    $myTemplate
}
Function ddPersnr-SelectionChanged {
    Get-UserAndPwd

    $script:window.rbPRV.IsEnabled = $true
    $script:window.rbRUDZL.IsEnabled = $true
    $script:window.rbOW.IsEnabled = $true
    $script:window.rbZRK.IsEnabled = $true
    $script:window.rbFM.IsEnabled = $true
    $script:window.rbSL.IsEnabled = $true
    $script:window.rbIntern.IsEnabled = $true
    $script:window.rbCAT.IsEnabled = $true
    $script:window.rbSM.IsEnabled = $true
    $script:window.rbExterne.IsEnabled = $true
            
    If ($env:COMPUTERNAME[-1] -ne 'h') { 
        $script:window.cbExchange.IsEnabled = $true
        $script:window.cbHomeDir.IsEnabled = $true
        $script:window.cbSkype.IsEnabled = $true
        $script:window.cbVDI.IsEnabled = $true
        $script:window.cbVodafone.IsEnabled = $true
    }
            
    $script:window.tbFirstname.Text = $script:persoon.ROEPNAAM
    $script:window.tbInitials.Text = $script:persoon.VOORLETTERS
    $script:window.tbLastname.Text = $script:persoon.ACHTERNAAM
    $script:window.tbDisplayname.Text = $script:persoon.DISPLAYNAAM
    $script:window.tbPrewin.Text = $script:persoon.VOORGESTELDE_ACCOUNT
    $script:window.tbAfd.Text = $script:persoon.ORG_OMS_WERKZ1
    $script:window.tbFunctie.Text = $script:persoon.FUNC1
    $script:window.tbWerkgever.Text = $script:persoon.WERKGEVER

    Set-Extras
    If (-not $script:userIsCreated) { 
        $script:conflict = Check-IfUserExists -check All
    }
    Add-toLog 'Kijk de gegevens na of alles klopt. We hebben al gecontroleerd of het account bestaat.'
    $script:window.tbPrewin.ToolTip = 'Klik op het veld om de inhoud naar het klembord te kopieren'
    If ($script:window.cbExchange.IsChecked) { 
        $script:window.ddDB.Focus()
        $script:window.ddDB.IsDropDownOpen = $true
    }
}
Function Show-InstallatieInstructie { 
    Param([boolean]$showFolder=$false)
    $path = '\\spl0009\Pl-Data-new\Organisatie en Informatie\I-Services\Technisch applicatiebeheer\DSL\Oracle client\ODAC_voor_powershell\ODAC122011_x64'
    $prompt = ("Oracle client installeren doe je in de beheer bak.`n`nDeze folder naar C:\Temp kopiëren:`n{0}`n`nAls admin predefined_install.bat starten" -f $path)
    If ($showFolder) { Start-Process -FilePath C:\Windows\explorer.exe -ArgumentList $path }
    Show-MsgBox -Prompt $prompt -Title 'Installatie' -BoxType OKOnly
}
Function Create-LoginDetails {
    #Script om credentials op te slaan om Oracle view uit te kunnen lezen
    If ($psISE) { 
        $filename = ('{0}\{1}.xml' -f $PSScriptRoot, $env:USERNAME)
    } Else { #$PSScriptRoot hebben we als executable niet
        #$process = get-process -Id $pid
        $process = Get-Process -Name Create-NewUser
        $path = Split-Path $process.Path
        $filename = ('{0}\{1}.xml' -f $path, $env:USERNAME)
    }
    If (-not (Test-Path $filename)) { 
        Write-Host "PID: $pid"
        Write-Host "Process: $($process.ProcessName)"
        Write-Host "$filename niet gevonden!"
        $cred = Get-Credential -Message 'Geef login gegevens om op de view van AFAS te kunnen inloggen. Staat bij TAB in KeePass.' -UserName 'afas_ws_ad_helpdesk'
        $cred | Export-Clixml -Path $filename 
    }
    $filename
}

Function Show-MsgBox { 
    #Show MessageBox and return the answer
    [CmdletBinding()] 
    param ( 
        [Parameter(Position=0, Mandatory=$true)] [string]$Prompt, 
        [Parameter(Position=1, Mandatory=$false)] [string]$Title ='', 
        [Parameter(Position=2, Mandatory=$false)] [ValidateSet('Information', 'Question', 'Critical', 'Exclamation')][string]$Icon ='Information', 
        [Parameter(Position=3, Mandatory=$false)] [ValidateSet('OKOnly', 'OKCancel', 'AbortRetryIgnore', 'YesNoCancel', 'YesNo', 'RetryCancel')][string]$BoxType ='OkOnly', 
        [Parameter(Position=4, Mandatory=$false)] [ValidateSet(1,2,3)] [int]$DefaultButton = 1 
    ) 
	
    [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null 
    $vb_icon = [microsoft.visualbasic.msgboxstyle]::$Icon
    $vb_box = [microsoft.visualbasic.msgboxstyle]::$BoxType
    $vb_defaultbutton = [microsoft.visualbasic.msgboxstyle]::"DefaultButton$Defaultbutton"
    $vb_MsgBoxSetForeground = [microsoft.visualbasic.msgboxstyle]::MsgBoxSetForeground
    
    $popuptype = $vb_icon -bor $vb_box -bor $vb_defaultbutton -bor $vb_MsgBoxSetForeground
    $answer = [Microsoft.VisualBasic.Interaction]::MsgBox($prompt,$popuptype,$title) 
    return $answer 
}
Function Connect-Oracle { 
    [CmdletBinding()] 
    param( 
        [Parameter(Mandatory=$true)]$connectionString 
    ) 
    
    $conn= New-Object Oracle.DataAccess.Client.OracleConnection($connectionString) 
    $conn.Open() 
    Return $conn 
} 
Function Get-DataTable{ 
    [CmdletBinding()] 
    Param( 
        [Parameter(Mandatory=$true)][Oracle.DataAccess.Client.OracleConnection]$conn, 
        [Parameter(Mandatory=$true)][string]$sql 
    ) 
		
    $cmd = New-Object Oracle.DataAccess.Client.OracleCommand($sql,$conn) 
    $da = New-Object Oracle.DataAccess.Client.OracleDataAdapter($cmd) 
    $dt = New-Object System.Data.DataTable 
    [void]$da.Fill($dt) 
    return $dt 
} 
Function Get-WS_PERSONEN_AD_ACCOUNT_LOOKUP { 
    #$filename = ('{0}\{1}.xml' -f $PSScriptRoot, $env:USERNAME)
    $cred = Import-Clixml $script:filename 

    $hostName = 'vlin019'
    $port = '1521'
    $sid = 'PIMS'

    #region Ophalen gegevens uit AFAS
    $odpAssemblyName = 'Oracle.DataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' 

    Try {
        [void][System.Reflection.Assembly]::Load($odpAssemblyName) 
    } Catch {
        $prompt = 'Je hebt de ODAC client niet geinstalleerd. bekijk de instructie in de volgende melding.'
        Show-MsgBox -Prompt $prompt -Title 'Oracle client' -Icon Critical -BoxType OKOnly
        Show-InstallatieInstructie -showFolder:$true
        Break
    }
    
    $dataSource = ('(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1}))(CONNECT_DATA=(SERVICE_NAME={2})))' -f $hostName, $port, $sid) 
    $connStr = ('Data Source={0};User Id={1};Password={2}' -f $dataSource, $cred.UserName, $cred.GetNetworkCredential().password)
    $view = 'WS_PERSONEN_AD_ACCOUNT_LOOKUP'
    $connection = Connect-Oracle -connectionString $connStr
    $SQLquery = "select * from $view"
    #Provinciale Staten mogen we niet aanpassen, behalve expiration date. Dat is een ander script.
    $oraData = Get-DataTable $connection $SQLquery 

    $connection.Close() 
    #endregion Ophalen gegevens uit AFAS
    $oraData
}
Function Get-RandomCharacters($length, $characters) {
    $random = 1..$length | ForEach-Object { Get-Random -Maximum $characters.length }
    $private:ofs=""
    return [String]$characters[$random]
}
Function Add-toLog {
    Param($text)
    If ($script:window.LOG.Text) { 
        $newline = [Char]10
        $script:window.LOG.Text = $script:window.LOG.Text + ("{0}{1}" -f $newline, $text)
    } Else { $script:window.LOG.Text = $text }
}
Function Get-UserAndPwd {
    $script:window.tbUserlogon.Text = $script:persoon.VOORGESTELDE_EMAIL.Split('@')[0] + $script:Orgs.$script:Template.UPN

    If (-not $script:window.tbWachtwoord.Text) {
        $password = Get-RandomCharacters -length 10 -characters 'abcdefghiklmnoprstuvwxyzABCDEFGHKLMNOPRSTUVWXYZ1234567890!$%&()=?}][{@#*+'
        $script:window.tbWachtwoord.Text = $password
    }
}

Function Set-Extras {
    If ($script:Orgs.$script:Template.Email -eq '') { 
        $script:window.cbExchange.IsChecked = $false
        $script:window.tbemail.Text = ''
    } Else {
        $script:window.cbExchange.IsChecked = $true
        $script:window.tbemail.Text = $script:Persoon.VOORGESTELDE_EMAIL.Split('@')[0] + $script:Orgs.$script:Template.Email
        $script:window.ddDB.SelectedIndex = Get-Random -Minimum 1 -Maximum 4
        Add-toLog 'Kijk welke mailbox DB je moet kiezen in het wekelijkse rapport van envreport@prvlimburg.nl'
    }
    If ($script:Orgs.$script:Template.HomeDir -eq '') { 
        $script:window.cbHomeDir.IsChecked = $false
    } Else {
        $script:window.cbHomeDir.IsChecked = $true
        $script:window.tbhomeDir.Text = $script:Orgs.$script:Template.HomeDir + $script:window.tbPrewin.Text
    }
    $script:window.cbSkype.IsChecked = $script:Orgs.$script:Template.SIP
    $script:window.cbVDI.IsChecked = $script:Orgs.$script:Template.VDI
    $script:window.cbVodafone.IsChecked = $script:Orgs.$script:Template.Vodafone
    $script:window.ddOU.SelectedValue = $script:orgs.$script:template.OU 
    
    If ($script:window.cbSkype.IsChecked) { $script:window.btSkype.Visibility = 'Visible' }
    Else { $script:window.btSkype.Visibility = 'Hidden' }
}

Function Hide-TemplatePRV {
    Param([ValidateSet('visible', 'hidden')]$visibility)
    
    $script:window.txtTemplatePRV.Visibility = $visibility
    $script:window.rbIntern.Visibility = $visibility
    $script:window.rbCAT.Visibility = $visibility
    $script:window.rbSM.Visibility = $visibility
}
#endregion
#region Code Behind

function Convert-XAMLtoWindow {
    param (
        [Parameter(Mandatory=$true)]
        [string]
        $XAML
    )
  
    Add-Type -AssemblyName PresentationFramework
  
    $reader = [XML.XMLReader]::Create([IO.StringReader]$XAML)
    $result = [Windows.Markup.XAMLReader]::Load($reader)
    $reader.Close()
    $reader = [XML.XMLReader]::Create([IO.StringReader]$XAML)
    while ($reader.Read()) {
        $name = $reader.GetAttribute('Name')
        if (!$name) { $name = $reader.GetAttribute('x:Name') }
        if($name)
        {$result | Add-Member NoteProperty -Name $name -Value $result.FindName($name) -Force}
    }
    $reader.Close()
    $result
}

function Show-WPFWindow {
    param (
        [Parameter(Mandatory=$true)]
        [Windows.Window]
        $Window
    )
  
    $result = $null
    $null   = $window.Dispatcher.InvokeAsync{
        $result = $window.ShowDialog()
        Set-Variable -Name result -Value $result -Scope 1
    }.Wait()
    $result
}
#endregion Code Behind

#region XAML window definition
$xaml = @'

<Window 
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="User aanmaken" Height="727.601" Width="600" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Topmost="True" Icon="\\spl0009\Pl-Data-new\Organisatie en Informatie\I-Services\Technisch applicatiebeheer\Documentatie\Powershell Scripts\Create-NewUser\add-user.ico">
    <Grid>
        <Menu DockPanel.Dock="Top" Height="19" Width="600" VerticalAlignment="Top" Background="#FFD7D7D7">
            <MenuItem Header="_Info">
                <MenuItem x:Name="Installatie" Header="_Installatie" />
                <MenuItem x:Name="Credits" Header="_Credits" />
                <Separator />
                <MenuItem x:Name="Exit" Header="_Exit" />
            </MenuItem>
        </Menu>

        <ComboBox x:Name="ddPersnr" Height="22" Margin="127,42,285,0" VerticalAlignment="Top" Width="182" BorderThickness="1,1,1,1" ToolTip="Als je het persnr in het klembord hebt, vullen we dit automatisch in als je met de mis over dit veld komt"/>

        <TextBlock x:Name="txtPersnr" Margin="10,42,474,0" VerticalAlignment="Top" Height="22" Width="111" Text="Personeelsnummer:" TextAlignment="Right" FontFamily="Segoe UI" HorizontalAlignment="Right"/>
        <TextBox x:Name="tbFirstname" Margin="127,69,285,0" VerticalAlignment="Top" Width="182" Height="22" IsReadOnly="True" Background="#FFD7D7D7" IsTabStop="False"/>
        <TextBlock x:Name="txtWerkgever" Margin="314,42,220,0" VerticalAlignment="Top" Height="22" Width="60" TextAlignment="Right" Text="Werkgever:" HorizontalAlignment="Right"/>
        <TextBox x:Name="tbWerkgever" Margin="379,42,28,0" VerticalAlignment="Top" Width="187" Height="22" IsReadOnly="True" Background="#FFD7D7D7" IsTabStop="False"/>
        <TextBox x:Name="tbInitials" Margin="379,69,28,0" VerticalAlignment="Top" Width="187" Height="22" IsReadOnly="True" Background="#FFD7D7D7" IsTabStop="False"/>
        <TextBlock x:Name="txtInitials" Margin="314,69,220,0" VerticalAlignment="Top" Height="22" Width="60" TextAlignment="Right" Text="Initials:" HorizontalAlignment="Right"/>
        <TextBlock x:Name="txtFirstname" Margin="10,69,473,0" VerticalAlignment="Top" Height="22" TextAlignment="Right" Text="First name:" HorizontalAlignment="Right"/>
        <TextBox x:Name="tbLastname" Margin="127,96,27,0" VerticalAlignment="Top" Width="440" Height="22" IsReadOnly="True" Background="#FFD7D7D7" IsTabStop="False"/>
        <TextBlock x:Name="txtLastname" Margin="10,96,474,0" VerticalAlignment="Top" Height="22" Width="110" TextAlignment="Right" Text="Last name:" HorizontalAlignment="Right"/>
        <TextBox x:Name="tbDisplayname" Margin="127,123,27,0" VerticalAlignment="Top" Width="440" Height="22" IsReadOnly="True" Background="#FFD7D7D7" IsTabStop="False"/>
        <TextBlock x:Name="txtDisplayname" Margin="10,123,474,0" VerticalAlignment="Top" Height="22" Width="110" TextAlignment="Right" Text="Display name:" HorizontalAlignment="Right"/>
        <TextBox x:Name="tbAfd" Margin="127,150,27,0" VerticalAlignment="Top" Width="440" Height="22" IsReadOnly="True" Background="#FFD7D7D7" IsTabStop="False"/>
        <TextBlock x:Name="txtAfd" Margin="10,150,474,0" VerticalAlignment="Top" Height="22" Width="110" TextAlignment="Right" Text="Afdeling:" HorizontalAlignment="Right"/>

        <TextBlock x:Name="txtFunctie" Margin="10,177,474,0" VerticalAlignment="Top" Height="22" Width="110" TextAlignment="Right" HorizontalAlignment="Right"><Run Language="nl-nl" Text="Functie:"/></TextBlock>
        <TextBox x:Name="tbFunctie" Margin="128,177,27,0" VerticalAlignment="Top" Width="439" Height="22" IsReadOnly="True" Background="#FFD7D7D7" IsTabStop="False"/>
        <TextBox x:Name="tbDescription" Margin="128,204,25,0" VerticalAlignment="Top" Width="441" Height="22" IsTabStop="False"/>
        <TextBlock x:Name="txtDescription" Margin="10,204,474,0" VerticalAlignment="Top" Height="22" Width="110" TextAlignment="Right" HorizontalAlignment="Right"><Run Text="Description:"/></TextBlock>
        <TextBox x:Name="tbUserlogon" Margin="128,231,26,0" VerticalAlignment="Top" Width="440" Height="22" AutomationProperties.HelpText="initialen.achternaam" ToolTip="initialen.achternaam" IsTabStop="False"/>
        <TextBlock x:Name="txtUserlogon" Margin="10,231,475,0" VerticalAlignment="Top" Height="22" TextAlignment="Right" Text="User logon:" HorizontalAlignment="Right"/>
        <TextBox x:Name="tbemail" Margin="128,258,26,0" VerticalAlignment="Top" Height="22" IsTabStop="False" ToolTip="Klik op het veld om de inhoud naar het klembord te kopieren" Cursor="Hand"/>
        <TextBlock x:Name="txtemail" Margin="10,258,473,0" VerticalAlignment="Top" Height="22" TextAlignment="Right" Text="Email:" HorizontalAlignment="Right"/>
        <TextBox x:Name="tbhomeDir" Margin="128,285,26,0" VerticalAlignment="Top" Height="22" IsTabStop="False"/>
        <TextBlock x:Name="txthomeDir" Margin="10,285,472,0" VerticalAlignment="Top" Height="22" TextAlignment="Right" Text="Home Dir:" HorizontalAlignment="Right"/>
        <TextBlock x:Name="txtWachtwoord" Margin="10,312,475,0" VerticalAlignment="Top" Height="22" TextAlignment="Right" Text="Wachtwoord:" HorizontalAlignment="Right"/>
        <TextBox x:Name="tbWachtwoord" Margin="128,312,242,0" VerticalAlignment="Top" Width="224" Height="22" IsReadOnly="True" Background="#FFD7D7D7" IsTabStop="False" ToolTip="Klik op het veld om de inhoud naar het klembord te kopieren" Cursor="Hand"/>
        <TextBlock x:Name="txtPrewin" Margin="356,312,193,0" VerticalAlignment="Top" Height="22" TextAlignment="Right" Text="pre-Win:" HorizontalAlignment="Right"/>
        <TextBox x:Name="tbPrewin" Margin="406,312,27,0" VerticalAlignment="Top" Height="22" AutomationProperties.HelpText="AchternaamINITIALEN" ToolTip="AchternaamINITIALEN" IsTabStop="False" Cursor="Hand"/>

        <TextBlock x:Name="txtOU" Margin="10,339,474,0" VerticalAlignment="Top" Height="22" Width="110" TextAlignment="Right" Text="OU:" HorizontalAlignment="Right"/>
        <ComboBox x:Name="ddOU" Height="22" Margin="128,339,242,0" VerticalAlignment="Top" Width="224">
        </ComboBox>
        <TextBlock x:Name="txtDB" Margin="356,339,193,0" VerticalAlignment="Top" Height="22" TextAlignment="Right" Text="DB:"/>
        <ComboBox x:Name="ddDB" Height="22" Margin="406,339,28,0" VerticalAlignment="Top" Width="160">
            <ComboBoxItem Content="DB01;Iedereen"/>
            <ComboBoxItem Content="DB02;Iedereen"/>
            <ComboBoxItem Content="DB03;Iedereen"/>
            <ComboBoxItem Content="DB04;Iedereen"/>
            <ComboBoxItem Content="DB05;Shared Mailboxen"/>
            <ComboBoxItem Content="DB06;Alleen GS en Directie!"/>
        </ComboBox>

        <Border x:Name="borderTemplate" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="61" Margin="49,374,0,0" VerticalAlignment="Top" Width="516"/>
        <TextBlock x:Name="txtTemplate" Margin="49,381,473,0" VerticalAlignment="Top" Height="22" TextAlignment="Right" Text="Template:"/>
        <RadioButton x:Name="rbPRV" Content="PRV" HorizontalAlignment="Left" Margin="128,382,0,0" VerticalAlignment="Top" GroupName="Template" IsChecked="True" ToolTip="Provincie Limburg, incl catering en schoonmaak" IsEnabled="False" RenderTransformOrigin="0.488,0.233"/>
        <RadioButton x:Name="rbRUDZL" Content="RUDZL" HorizontalAlignment="Left" Margin="185,382,0,0" VerticalAlignment="Top" GroupName="Template" ToolTip="Regionale Uitvoeringsdienst Zuid-Limburg" IsEnabled="False"/>
        <RadioButton x:Name="rbOW" Content="OW" HorizontalAlignment="Left" Margin="263,382,0,0" VerticalAlignment="Top" GroupName="Template" ToolTip="Ooijen-Wanssum" IsEnabled="False"/>
        <RadioButton x:Name="rbZRK" Content="ZRK" HorizontalAlignment="Left" Margin="319,382,0,0" VerticalAlignment="Top" GroupName="Template" ToolTip="Zuidelijke Rekenkamer via concern geen e-mail" IsEnabled="False"/>
        <RadioButton x:Name="rbFM" Content="FM" HorizontalAlignment="Left" Margin="379,382,0,0" VerticalAlignment="Top" GroupName="Template" ToolTip="Fractiemedewerker" IsEnabled="False"/>
        <RadioButton x:Name="rbSL" Content="SL/BCL" HorizontalAlignment="Left" Margin="428,382,0,0" VerticalAlignment="Top" GroupName="Template" ToolTip="Statenlid en Burgercommissielid" IsEnabled="False"/>
        <RadioButton x:Name="rbExterne" Content="Externe" HorizontalAlignment="Left" Margin="494,382,0,0" VerticalAlignment="Top" GroupName="Template" ToolTip="Externen die via VPN support geven" IsEnabled="False"/>

        <TextBlock x:Name="txtTemplatePRV" HorizontalAlignment="Left" Margin="49,408,0,0" VerticalAlignment="Top" Height="22" Width="72" TextAlignment="Right" Text="Provincie:"/>
        <RadioButton x:Name="rbIntern" Content="Intern" HorizontalAlignment="Left" Margin="127,408,0,0" VerticalAlignment="Top" GroupName="TemplatePRV" IsChecked="True" ToolTip="Provincie Limburg" IsEnabled="False"/>
        <RadioButton x:Name="rbCAT" Content="Catering" HorizontalAlignment="Left" Margin="185,408,0,0" VerticalAlignment="Top" GroupName="TemplatePRV" ToolTip="Provincie Limburg, Catering via Facilitair" IsEnabled="False"/>
        <RadioButton x:Name="rbSM" Content="Schoonmaak" HorizontalAlignment="Left" Margin="263,408,0,0" VerticalAlignment="Top" GroupName="TemplatePRV" ToolTip="Provincie Limburg, Schoonmaak via Facilitair" IsEnabled="False"/>

        <Border x:Name="borderExtra" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="42" Margin="49,440,0,0" VerticalAlignment="Top" Width="516"/>
        <TextBlock x:Name="txtExtra" HorizontalAlignment="Left" Margin="49,449,0,0" VerticalAlignment="Top" Height="22" Width="70" TextAlignment="Right" Text="Extra:"/>
        <CheckBox x:Name="cbExchange" Content="Exchange" HorizontalAlignment="Left" Margin="124,451,0,0" VerticalAlignment="Top" IsChecked="True" IsEnabled="False"/>
        <CheckBox x:Name="cbSkype" Content="Skype" HorizontalAlignment="Left" Margin="201,451,0,0" VerticalAlignment="Top" IsChecked="True" IsEnabled="False"/>
        <CheckBox x:Name="cbHomeDir" Content="HomeDir" HorizontalAlignment="Left" Margin="257,451,0,0" VerticalAlignment="Top" IsChecked="True" IsEnabled="False"/>
        <CheckBox x:Name="cbVDI" Content="VDI" HorizontalAlignment="Left" Margin="333,451,0,0" VerticalAlignment="Top" IsChecked="True" IsEnabled="False"/>
        <CheckBox x:Name="cbVodafone" Content="Vodafone" HorizontalAlignment="Left" Margin="393,451,0,0" VerticalAlignment="Top" IsChecked="True" IsEnabled="False"/>

        <Image x:Name="LOGO" HorizontalAlignment="Left" Height="54" Margin="383,642,0,0" VerticalAlignment="Top" Width="182" Source="\\spl0007\Pl-Data-new\Organisatie en Informatie\I-Services\Technisch applicatiebeheer\Documentatie\Powershell Scripts\Create-NewUser\logo-pl-full.png"/>

        <TextBox x:Name="LOG" HorizontalAlignment="Left" Height="90" Margin="49,487,0,0" VerticalAlignment="Top" Width="516" Background="#FFD7D7D7" IsReadOnly="True" ForceCursor="True" Foreground="Red" Text="Zoek in het veld personeelsnummer de medewerker op en druk daarna op de tab toets. Kijk dan alle gegevens na of alles klopt." IsTabStop="False" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"/>
        <Button x:Name="btAanmakenUser" Content="btAanmakenUser" HorizontalAlignment="Left" Height="35" Margin="45,602,0,0" VerticalAlignment="Top" Width="35" Cursor="Hand">
            <Button.Template>
                <ControlTemplate>
                    <Border x:Name="aanmakenUserBorder" BorderBrush="Transparent" BorderThickness="2">
                        <Image Source="\\spl0007\Pl-Data-new\Organisatie en Informatie\I-Services\Technisch applicatiebeheer\Documentatie\Powershell Scripts\Create-NewUser\add-user.png" Height="35" Width="35"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" TargetName="aanmakenUserBorder" Value="LightSkyBlue"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Button.Template>
        </Button>

        <Button x:Name="btSkype" Content="btSkype" HorizontalAlignment="Left" Height="35" Margin="86,602,0,0" VerticalAlignment="Top" Width="35" Cursor="Hand" ToolTip="Activeer Skype voor de gebruiker">
            <Button.Template>
                <ControlTemplate>
                    <Border x:Name="skypeBorder" BorderBrush="Transparent" BorderThickness="2">
                        <Image Source="\\spl0007\Pl-Data-new\Organisatie en Informatie\I-Services\Technisch applicatiebeheer\Documentatie\Powershell Scripts\Create-NewUser\_Skype.png" Height="35" Width="35"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" TargetName="skypeBorder" Value="LightSkyBlue"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Button.Template>
        </Button>

        <Button x:Name="btTopdesk" Content="btTopdesk" Height="35" Margin="126,602,0,0" Width="35" Cursor="Hand" ToolTip="Kopieer Topdesk info naar het klembord" HorizontalAlignment="Left" VerticalAlignment="Top">
            <Button.Template>
                <ControlTemplate>
                    <Border x:Name="topdeskBorder" BorderBrush="Transparent" BorderThickness="2">
                        <Image Source="\\spl0007\Pl-Data-new\Organisatie en Informatie\I-Services\Technisch applicatiebeheer\Documentatie\Powershell Scripts\Create-NewUser\Topdesk.png" Height="35" Width="35"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" TargetName="topdeskBorder" Value="LightSkyBlue"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Button.Template>
        </Button>

        <Button Name="btStoppen" Content="Afsluiten" HorizontalAlignment="Left" Height="30" Margin="45,642,0,0" VerticalAlignment="Top" Width="116" IsTabStop="False"/>
    </Grid>
</Window>

'@
#endregion XAML window definition

#region algemeen stukje voor het script
$Error.Clear()
Clear-Host
$filename = Create-LoginDetails 
$folder = Split-Path $filename
Start-Transcript "$folder\Create-NewUser.log"
$userIsCreated = $false
$orgs = @{}
$orgs.PRV = @{'template'='templateprvl'
    'UPN'='@prvlimburg.nl'
    'Email'='@prvlimburg.nl'
    'OU'='OU=Gebruikers,OU=PL,DC=prvlimburg,DC=nl'
    'HomeDir'='\\spl0007\homexp$\'
    'MailDB' = 1
    'ABP'='Provincie Limburg'
    'SIP'=$true
    'VDI'=$true
    'Vodafone'=$true}
#Catering    
$orgs.CAT = @{'template'='templateprvl'
    'UPN'='@prvlimburg.nl'
    'Email'=''
    'OU'='OU=Gebruikers,OU=PL,DC=prvlimburg,DC=nl'
    'HomeDir'='\\spl0007\homexp$\'
    'MailDB' = ''
    'ABP'=''
    'SIP'=$false
    'VDI'=$true
    'Vodafone'=$false}
#Schoonmaak
$orgs.SM = @{'template'='templateprvl'
    'UPN'='@prvlimburg.nl'
    'Email'=''
    'OU'='OU=Gebruikers,OU=PL,DC=prvlimburg,DC=nl'
    'HomeDir'='\\spl0007\homexp$\'
    'MailDB' = ''
    'ABP'=''
    'SIP'=$false
    'VDI'=$true
    'Vodafone'=$false}
$orgs.RUDZL = @{'template'='templaterudzl'
    'UPN'='@rudzl.nl'
    'Email'='@rudzl.nl'
    'OU'='OU=Gebruikers,OU=orgRUDZL,DC=prvlimburg,DC=nl'
    'HomeDir'='\\rudzl\l-rudzl\'
    'MailDB' = 4
    'ABP'='RUDZL'
    'SIP'=$false
    'VDI'=$true
    'Vodafone'=$true}
#Ooijen-Wanssum
$orgs.OW = @{'template'='templateow'
    'UPN'='@ooijen-wanssum.nl'
    'Email'='@ooijen-wanssum.nl'
    'OU'='OU=Gebruikers,OU=orgOW,DC=prvlimburg,DC=nl'
    'HomeDir'='\\ow\l-ow\'
    'MailDB' = 4
    'ABP'='Ooijen-Wanssum'
    'SIP'=$false
    'VDI'=$true
    'Vodafone'=$false}
#Zuidelijke rekenkamer
$orgs.ZRK = @{'template'=''
    'UPN'='@prvlimburg.nl'
    'Email'=''; 
    'OU'='OU=Gebruikers,OU=PL,DC=prvlimburg,DC=nl'
    'HomeDir'='\\spl0007\homexp$\'
    'MailDB' = ''
    'ABP'=''
    'SIP'=$false
    'VDI'=$false
    'Vodafone'=$false}
#fractiemedewerker
$orgs.FM = @{'template'=''; 
    'UPN'='@prvlimburg.nl'
    'Email'=''
    'OU'='OU=Fractiemedewerkers,OU=Externen,DC=prvlimburg,DC=nl'
    'HomeDir'=''
    'MailDB' = ''
    'ABP'=''
    'SIP'=$false
    'VDI'=$false
    'Vodafone'=$false}
#Statenleden en Burgercommissieleden
$orgs.SL = @{'template'=''
    'UPN'='@prvlimburg.nl'
    'Email'='@prvlimburg.nl'
    'OU'='OU=Statenleden,OU=PL,DC=prvlimburg,DC=nl'
    'HomeDir'=''
    'MailDB' = 1
    'ABP'='Provincie Limburg'
    'SIP'=$false
    'VDI'=$false
    'Vodafone'=$false}
#Externe
$orgs.Externe = @{'template'=''
    'UPN'='@externen.nl'
    'Email'=''
    'OU'='OU=Externen SSLVPN,OU=Externen,DC=prvlimburg,DC=nl'
    'HomeDir'=''
    'MailDB' = ''
    'ABP'=''
    'SIP'=$false
    'VDI'=$false
    'Vodafone'=$false}


$template = 'PRV'
#Ophalen AFAS gegevens
$oraData = Get-WS_PERSONEN_AD_ACCOUNT_LOOKUP | Sort REGISTRATIE_NR -Descending
$persLijst = $oraData | Select @{N='Line'; E={ ('{0}; {1}; {2}; {3}' -f $_.REGISTRATIE_NR, $_.DISPLAYNAAM, $_.FUNC1, $_.WERKGEVER) }} | Select -ExpandProperty Line
#endregion algemeen stukje voor het script

#region Convert XAML to Window
$window = Convert-XAMLtoWindow -XAML $xaml 
#endregion

#region Define Event Handlers
#Vasthouden welk template gekozen is
$window.rbPRV.add_Checked({
        $script:template = 'PRV'
        Get-UserAndPwd
        Set-Extras
})
$window.rbRUDZL.add_Checked({
        $script:template = 'RUDZL'
        Get-UserAndPwd
        Set-Extras
})
$window.rbOW.add_Checked({
        $script:template = 'OW'
        Get-UserAndPwd
        Set-Extras
})
$window.rbZRK.add_Checked({
        $script:template = 'ZRK'
        Get-UserAndPwd
        Set-Extras
        Add-toLog 'Zuidelijke rekenkamer via Johan'
})
$window.rbFM.add_Checked({
        $script:template = 'FM'
        Get-UserAndPwd
        Set-Extras
        Add-toLog 'Fractiemedewerkers via Johan'
})
$window.rbSL.add_Checked({
        $script:template = 'SL'
        Get-UserAndPwd
        Set-Extras
        $script:window.rbIntern.IsEnabled = $false
        $script:window.rbCAT.IsEnabled = $false
        $script:window.rbSM.IsEnabled = $false
        Add-toLog 'Statenleden en burgercommissieleden via Johan'
})
$window.rbExterne.add_Checked({
        $script:template = 'Externe'
        Get-UserAndPwd
        Set-Extras
        Add-toLog 'Externen via TB of FB. Als het account is aangemaakt, moet je in AD bij het email veld hun eigen mail adres zetten. Vermeld ook hun 06 nummer in het AD account.'
        Add-toLog 'Moet er een geheimhoudings verklaring ondertekend worden (regelen via Leon Deben)?'
})
$window.rbIntern.add_Checked({
        $script:template = 'PRV'
        Get-UserAndPwd
        Set-Extras
})
$window.rbCAT.add_Checked({
        $script:template = 'CAT'
        Get-UserAndPwd
        Set-Extras
})
$window.rbSM.add_Checked({
        $script:template = 'SM'
        Get-UserAndPwd
        Set-Extras
})

$window.ddPersnr.add_MouseEnter({
        If ($window.ddPersnr.SelectedIndex -eq -1) { 
            $clip = Get-Clipboard
            If ($clip -match '^\d{9}$' -and $clip -gt 10000) { #Pernr -gt 10000. Als we 9999 nieuwe medewerkers verder zijn werkt dit niet meer.
                $selected = $persLijst | Where { $_ -like "$clip*" }
                If ($selected) { 
                    $window.ddPersnr.SelectedValue = $selected
                    $window.LOG.Text = $null
                    $script:persoon = Get-Persoon
                    $script:Template = Get-Template
                    ddPersnr-SelectionChanged
                } Else { 
                    $window.ddPersnr.IsDropDownOpen = $true
                }
            } Else { 
                $window.ddPersnr.IsDropDownOpen = $true
            }
        }
})
$window.ddPersnr.add_SelectionChanged({ #LostFocus({
        If ($window.ddPersnr.SelectedValue -ne $null -and $window.ddPersnr.SelectedValue -ne '') {
            $window.LOG.Text = $null
            $script:persoon = Get-Persoon
            $script:Template = Get-Template
            ddPersnr-SelectionChanged
        } Else {
            $window.LOG.Text = 'Geen gebruiker geselecteerd'
            $window.ddPersnr.Text = ''
        }
})

$window.tbPrewin.add_LostFocus({
        If (-not $script:userIsCreated) { 
            $script:conflict = Check-IfUserExists -check samAccountName
        }
})
$window.tbUserlogon.add_LostFocus({
        If (-not $script:userIsCreated) { 
            $script:conflict = Check-IfUserExists -check UserPrincipalName
        }
})
$window.tbemail.add_LostFocus({
        If (-not $script:userIsCreated) { 
            $script:conflict = Check-IfUserExists -check mail
        }
})
$window.tbDisplayname.add_LostFocus({
        If (-not $script:userIsCreated) { 
            $script:conflict = Check-IfUserExists -check Displayname
        }
})

$window.tbWachtwoord.add_GotFocus({
        $window.tbWachtwoord.Text | clip
})
$window.tbPrewin.add_GotFocus({
        $window.tbPrewin.Text | clip
})
$window.tbemail.add_GotFocus({
        $window.tbemail.Text | clip
})
$window.btTopdesk.add_GotFocus({
        Copy-ToClipboard
})

$window.btAanmakenUser.add_Click({
        If (-not $script:conflict) { 
            $answer = Show-MsgBox -Prompt 'Weet je zeker dat je deze gebruiker wilt aanmaken' -Title 'Controle' -Icon Question -BoxType YesNo
            If ($answer -eq 'Yes') {
                $script:userIsCreated = $true
                $script:window.ddPersnr.IsEnabled = $false
                
                Create-ADUser
                Start-Sleep -Seconds 5
                If ($window.cbExchange.IsChecked) { Create-UserMailbox }
                If ($window.cbHomeDir.IsChecked) { Create-HomeDir }
                Add-toLog -text 'Gebruik nu de andere knoppen om het account af te maken'
            }
        } Else {
            $prompt = 'Er bestaat een conflict met een bestaande gebruiker, je moet dat eerst oplossen'
            Show-MsgBox -Prompt $prompt -Title 'Conflict' -Icon Critical -BoxType OKOnly
        }
})

$window.btStoppen.add_Click({ 
        $window.DialogResult = $true
        $window.Close() 
})

$window.btSkype.add_Click({
        Start-Process -FilePath 'C:\Program Files\internet explorer\iexplore.exe' -ArgumentList 'https://vspl2023.prvlimburg.nl/cscp/'
})

$window.Installatie.add_Click({
        Show-InstallatieInstructie
})
$window.Exit.add_Click({
        $window.Close()
        Break
})
$window.Credits.add_Click({
        $prompt = "************************`nScript:`nPascal Zeptner`nMark Snijders`nLuc Possen `n`nOracle/AFAS:`nHarold Dassen`n************************"
        Show-MsgBox -Prompt $prompt -Title 'Credits' -BoxType OKOnly
})

#endregion Event Handlers

#region Manipulate Window Content
$OUs = 'OU=Gebruikers,OU=PL,DC=prvlimburg,DC=nl', 'OU=Gebruikers,OU=orgRUDZL,DC=prvlimburg,DC=nl', 'OU=Gebruikers,OU=orgOW,DC=prvlimburg,DC=nl', 'OU=Gebruikers,OU=PL,DC=prvlimburg,DC=nl', 'OU=Fractiemedewerkers,OU=Externen,DC=prvlimburg,DC=nl', 'OU=Statenleden,OU=PL,DC=prvlimburg,DC=nl', 'OU=Externen SSLVPN,OU=Externen,DC=prvlimburg,DC=nl'
$window.ddOU.ItemsSource = $OUs
$window.ddPersnr.ItemsSource = $persLijst
#endregion

# Show Window
$result = Show-WPFWindow -Window $window


#region Process results
if ($result -eq $true) {
    If ($error) {
        $MessageBody = ("Er zijn fouten opgetreden. Kijk deze gebruiker goed na.`n`n{0}" -f ($Error.Exception.Message -join("`n")))
        $MessageTitle = "Fouten ontdekt"
        $result = Show-MsgBox -Prompt $MessageBody -Title $MessageTitle -Icon Exclamation -BoxType OKOnly        
    }
    $MessageBody = "Gebruiker is aangemaakt, Wil je opnieuw beginnen?"
    $MessageTitle = "Klaar"
    $result = Show-MsgBox -Prompt $MessageBody -Title $MessageTitle -Icon Question -BoxType YesNo

    if ($Result -eq "Yes") {
        If ($psISE) { 
            $pathToSelf = $PSCommandPath
        } Else {
            $process = Get-Process -Id $pid
            $pathToSelf = $process.Path
        }
        Start-Process -FilePath $pathToSelf
        return
    }
}

#endregion Process results



# SIG # Begin signature block
# MIIPGAYJKoZIhvcNAQcCoIIPCTCCDwUCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUllWoJeI0Pgs06xLSZZ8Ax9xB
# 7yagggyEMIIF5TCCA82gAwIBAgITEwAAAAdt5ed5G5Nb4AAAAAAABzANBgkqhki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