Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase, System.Windows.Forms, System.Drawing
[xml]$XML = @"
16
16
"@
[xml]$XML2 = @"
"@
$FormXML = (New-Object System.Xml.XmlNodeReader $XML)
$Window = [Windows.Markup.XamlReader]::Load($FormXML)
$XML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object {
New-Variable -Name $_.Name -Value $Window.FindName($_.Name) -Force
# Write-host $_.Name
}
function Get-RandomPassword{
Param(
[Parameter(mandatory=$true)]
[int]$Length
)
Begin{
if($Length -lt 4){
End
}
$Numbers = 2..9
$LettersLower = 'abcdefghjkmnpqrstuvwxyz'.ToCharArray()
$LettersUpper = 'ABCEDEFGHJKLMNPQRSTUVWXYZ'.ToCharArray()
$Special = '!@#$%&*?'.ToCharArray()
#For the 4 character types (upper, lower, numerical, and special)
$N_Count = [math]::Round($Length*.2)
$L_Count = [math]::Round($Length*.4)
$U_Count = [math]::Round($Length*.2)
$S_Count = [math]::Round($Length*.2)
}
Process{
$Pwd = $LettersLower | Get-Random -Count $L_Count
$Pwd += $Numbers | Get-Random -Count $N_Count
$Pwd += $LettersUpper | Get-Random -Count $U_Count
$Pwd += $Special | Get-Random -Count $S_Count
if($Pwd.length -lt $Length){
$Pwd += $LettersLower | Get-Random -Count ($Length - $Pwd.length)
}
#Lastly, grab the $Pwd string and randomize the order
$Pwd = ($Pwd | Get-Random -Count $Length) -join ""
}
End{
$Pwd
}
}
#Définition des variables
$Suffixe_UPN = (Get-ADDomain).DNSRoot
$DN_Domain = (Get-ADDomain).DistinguishedName
$Structure = Get-ADOrganizationalUnit -Filter 'State -ne "$null"' -SearchScope 1 | Select Name, DistinguishedName,@{N="Structure";E={if ($_.Name -ne "Global") {(($_.State).Split("|")[1]).Trim()} else {"Global"}}},@{N="Acr_Structure";E={(($_.State).Split("|")[0]).Trim()}}
# if (!(Test-Path "C:\Sources")) {New-Item "C:\Sources" -ItemType Directory | Out-Null}
# $Filename = "C:\Sources\$((Get-Date).ToString('ddMMyyyy'))_creation_comptes.txt"
# $ADUsers = Get-ADUser -Filter * | Select SamAccountName, UserPrincipalName
# Action Créer Comptes admin
$BTN_AjoutCompteAdmin.Add_Click({
if (($TB_NomUtilisateur.text -eq '') -or ($TB_PrenomUtilisateur.text -eq '') -or ($CB_StructureUtilisateur.SelectedItem -eq $null)) {
[System.Windows.Forms.MessageBox]::Show("Renseignez les champs.")
} Else {
$ADUsers = Get-ADUser -Filter * | Select SamAccountName, UserPrincipalName
$Prenom = $TB_PrenomUtilisateur.text
$Nom = $TB_NomUtilisateur.text
$Nom_Structure = $CB_StructureUtilisateur.SelectedItem
$Acronyme_Structure = ($Structure | Where {$_.Name -eq $Nom_Structure}).Acr_Structure
$Acronyme_Global = ($Structure | Where {$_.Name -eq "Global"}).Acr_Structure
$Grp_Admins_SRV = "GS-$($Acronyme_Structure)-Admins-SRV"
$Grp_Admins_NTK = "GS-$($Acronyme_Structure)-Admins-NTK"
$Grp_Admins_PC = "GS-$($Acronyme_Structure)-Admins-PC"
$Grp_PSO_Admins_SRV = "GS-$($Acronyme_Global)-PSO-Admins-SRV"
$Grp_PSO_Admins_PC = "GS-$($Acronyme_Global)-PSO-Admins-PC"
if ($Nom_Structure -eq "Global") {
if ($CB_AdminDomaine.IsChecked) {
$DisplayName = "Dom $Prenom $Nom"
# $UPN = (("dom." + ($TB_NomUtilisateur.text).ToLower()) -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i") + '@' + $Suffixe_UPN
[string]$UPN = (("dom." + ($TB_UPNUtilisateur.Text.Substring($TB_UPNUtilisateur.Text.IndexOf('.') + 1))))
# $SAM_dom = ("dom." + ($TB_NomUtilisateur.text).ToLower()) -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i"
[string]$SAM_dom = (("dom." + ($TB_SamAccountNameUtilisateur.Text.Substring($TB_SamAccountNameUtilisateur.Text.IndexOf('.') + 1))))
$OU = "OU=Domaine,OU=Admins,OU=Global,$DN_Domain"
# $Pwd_dom = Get-RandomPassword -Length 16
if ((($ADUsers | Where {$_.SamAccountName -eq $SAM_dom}).SamAccountName -ne $SAM_dom) -and (($ADUsers | Where {$_.UserPrincipalName -eq $UPN}).UserPrincipalName -ne $UPN)) {
$Pwd_dom = Get-RandomPassword -Length 16
New-ADUser -Name $DisplayName -GivenName $Prenom -Surname $Nom -DisplayName $DisplayName -UserPrincipalName $UPN -SamAccountName $SAM_dom -Path $OU -AccountNotDelegated $true -AccountPassword (ConvertTo-SecureString $Pwd_dom -AsPlainText -Force) -Enabled $true
$Dom_User = Get-ADUser -Identity $SAM_dom
$AdminsDom = Get-ADGroup -identity 'Admins du domaine'
Add-ADGroupMember -Identity $AdminsDom -Members $Dom_User
# Write-Output "$Prenom;$nom;$SAM_dom;$UPN;$Nom_Structure;$Pwd_dom" | Out-File -FilePath $Filename -Append
} else {
[System.Windows.Forms.MessageBox]::Show("Le compte $UPN est déjà présent.", "Création Administrateur" , 0, 64)
}
}
if (($CB_AdminServeurs.IsChecked) -or ($CB_AdminNTK.IsChecked)) {
$DisplayName = "Admin $Prenom $Nom"
# $UPN = (("admin." + ($TB_NomUtilisateur.text).ToLower()) -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i") + '@' + $Suffixe_UPN
$UPN = (("admin." + ($TB_UPNUtilisateur.Text.Substring($TB_UPNUtilisateur.Text.IndexOf('.') + 1))))
# $SAM_admin = ("admin." + ($TB_NomUtilisateur.text).ToLower()) -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i"
$SAM_admin = (("admin." + ($TB_SamAccountNameUtilisateur.Text.Substring($TB_SamAccountNameUtilisateur.Text.IndexOf('.') + 1))))
$OU = "OU=Serveur - Périphérique - Application,OU=Admins,OU=Global,$DN_Domain"
# $Pwd_admin = Get-RandomPassword -Length 12
if ((($ADUsers | Where {$_.SamAccountName -eq $SAM_admin}).SamAccountName -ne $SAM_admin) -and (($ADUsers | Where {$_.UserPrincipalName -eq $UPN}).UserPrincipalName -ne $UPN)) {
$Pwd_admin = Get-RandomPassword -Length 12
New-ADUser -Name $DisplayName -GivenName $Prenom -Surname $Nom -DisplayName $DisplayName -UserPrincipalName $UPN -SamAccountName $SAM_admin -Path $OU -AccountNotDelegated $true -AccountPassword (ConvertTo-SecureString $Pwd_admin -AsPlainText -Force) -Enabled $true
$Admin_User = Get-ADUser -Identity $SAM_admin
if ($CB_AdminServeurs.IsChecked) {
$GroupStructureSRV = Get-ADGroup -identity $Grp_Admins_SRV
Add-ADGroupMember -Identity $GroupStructureSRV -Members $Admin_User
}
if ($CB_AdminNTK.IsChecked) {
$GroupStructureNTK = Get-ADGroup -identity $Grp_Admins_NTK
Add-ADGroupMember -Identity $GroupStructureNTK -Members $Admin_User
}
$GroupStructurePSO_SRV = Get-ADGroup -identity $Grp_PSO_Admins_SRV
Add-ADGroupMember -Identity $GroupStructurePSO_SRV -Members $Admin_User
# Write-Output "$Prenom;$nom;$SAM_admin;$UPN;$Nom_Structure;$Pwd" | Out-File -FilePath $Filename -Append
} else {
[System.Windows.Forms.MessageBox]::Show("Le compte $UPN est déjà présent.", "Création Administrateur" , 0, 64)
}
}
if ($CB_AdminPC.IsChecked) {
$DisplayName = "PC $Prenom $Nom"
# $UPN = (("pc." + ($TB_NomUtilisateur.text).ToLower()) -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i") + '@' + $Suffixe_UPN
$UPN = (("pc." + ($TB_UPNUtilisateur.Text.Substring($TB_UPNUtilisateur.Text.IndexOf('.') + 1))))
# $SAM_pc = ("pc." + ($TB_NomUtilisateur.text).ToLower()) -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i"
$SAM_pc = (("pc." + ($TB_SamAccountNameUtilisateur.Text.Substring($TB_SamAccountNameUtilisateur.Text.IndexOf('.') + 1))))
$OU = "OU=Poste Utilisateur,OU=Admins,OU=Global,$DN_Domain"
# $Pwd_pc = Get-RandomPassword -Length 10
if ((($ADUsers | Where {$_.SamAccountName -eq $SAM_pc}).SamAccountName -ne $SAM_pc) -and (($ADUsers | Where {$_.UserPrincipalName -eq $UPN}).UserPrincipalName -ne $UPN)) {
$Pwd_pc = Get-RandomPassword -Length 10
New-ADUser -Name $DisplayName -GivenName $Prenom -Surname $Nom -DisplayName $DisplayName -UserPrincipalName $UPN -SamAccountName $SAM_pc -Path $OU -AccountNotDelegated $true -AccountPassword (ConvertTo-SecureString $Pwd_pc -AsPlainText -Force) -Enabled $true
$PC_User = Get-ADUser -Identity $SAM_pc
$AdminsPC = Get-ADGroup -identity $Grp_Admins_PC
Add-ADGroupMember -Identity $AdminsPC -Members $PC_User
Add-ADGroupMember -Identity $Grp_PSO_Admins_PC -Members $PC_User
# Write-Output "$Prenom;$nom;$SAM_pc;$UPN;$Nom_Structure;$Pwd_pc" | Out-File -FilePath $Filename -Append
} else {
[System.Windows.Forms.MessageBox]::Show("Le compte $UPN est déjà présent.", "Création Administrateur" , 0, 64)
}
}
} else {
if (($CB_AdminServeurs.IsChecked) -or ($CB_AdminNTK.IsChecked)) {
$DisplayName = "Admin $Prenom $Nom"
# $UPN = (("admin." + ($TB_NomUtilisateur.text).ToLower()) -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i") + '@' + $Suffixe_UPN
$UPN = (("admin." + ($TB_UPNUtilisateur.Text.Substring($TB_UPNUtilisateur.Text.IndexOf('.') + 1))))
# $SAM_admin = ("admin." + ($TB_NomUtilisateur.text).ToLower()) -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i"
$SAM_admin = (("admin." + ($TB_SamAccountNameUtilisateur.Text.Substring($TB_SamAccountNameUtilisateur.Text.IndexOf('.') + 1))))
$OU = "OU=Serveur - Périphérique - Application,OU=Admins,OU=$($Nom_Structure),$DN_Domain"
# $Pwd_admin = Get-RandomPassword -Length 12
if ((($ADUsers | Where {$_.SamAccountName -eq $SAM_admin}).SamAccountName -ne $SAM_admin) -and (($ADUsers | Where {$_.UserPrincipalName -eq $UPN}).UserPrincipalName -ne $UPN)) {
$Pwd_admin = Get-RandomPassword -Length 12
New-ADUser -Name $DisplayName -GivenName $Prenom -Surname $Nom -DisplayName $DisplayName -UserPrincipalName $UPN -SamAccountName $SAM_admin -Path $OU -AccountNotDelegated $true -AccountPassword (ConvertTo-SecureString $Pwd_admin -AsPlainText -Force) -Enabled $true
$Admin_User = Get-ADUser -Identity $SAM_admin
if ($CB_AdminServeurs.IsChecked) {
$GroupStructureSRV = Get-ADGroup -identity $Grp_Admins_SRV
Add-ADGroupMember -Identity $GroupStructureSRV -Members $Admin_User
}
if ($CB_AdminNTK.IsChecked) {
$GroupStructureNTK = Get-ADGroup -identity $Grp_Admins_NTK
Add-ADGroupMember -Identity $GroupStructureNTK -Members $Admin_User
}
$GroupStructurePSO_SRV = Get-ADGroup -identity $Grp_PSO_Admins_SRV
Add-ADGroupMember -Identity $GroupStructurePSO_SRV -Members $Admin_User
# Write-Output "$Prenom;$nom;$SAM_admin;$UPN;$Nom_Structure;$Pwd" | Out-File -FilePath $Filename -Append
} else {
[System.Windows.Forms.MessageBox]::Show("Le compte $UPN est déjà présent.", "Création Administrateur" , 0, 64)
}
}
if ($CB_AdminPC.IsChecked) {
$DisplayName = "PC $Prenom $Nom"
# $UPN = (("pc." + ($TB_NomUtilisateur.text).ToLower()) -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i") + '@' + $Suffixe_UPN
$UPN = (("pc." + ($TB_UPNUtilisateur.Text.Substring($TB_UPNUtilisateur.Text.IndexOf('.') + 1))))
# $SAM_pc = ("pc." + ($TB_NomUtilisateur.text).ToLower()) -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i"
$SAM_pc = (("pc." + ($TB_SamAccountNameUtilisateur.Text.Substring($TB_SamAccountNameUtilisateur.Text.IndexOf('.') + 1))))
$OU = "OU=Poste Utilisateur,OU=Admins,OU=$($Nom_Structure),$DN_Domain"
# $Pwd_pc = Get-RandomPassword -Length 10
if ((($ADUsers | Where {$_.SamAccountName -eq $SAM_pc}).SamAccountName -ne $SAM_pc) -and (($ADUsers | Where {$_.UserPrincipalName -eq $UPN}).UserPrincipalName -ne $UPN)) {
$Pwd_pc = Get-RandomPassword -Length 10
New-ADUser -Name $DisplayName -GivenName $Prenom -Surname $Nom -DisplayName $DisplayName -UserPrincipalName $UPN -SamAccountName $SAM_pc -Path $OU -AccountNotDelegated $true -AccountPassword (ConvertTo-SecureString $Pwd_pc -AsPlainText -Force) -Enabled $true
$PC_User = Get-ADUser -Identity $SAM_pc
$AdminsPC = Get-ADGroup -identity $Grp_Admins_PC
Add-ADGroupMember -Identity $AdminsPC -Members $PC_User
Add-ADGroupMember -Identity $Grp_PSO_Admins_PC -Members $PC_User
# Write-Output "$Prenom;$nom;$SAM_pc;$UPN;$Nom_Structure;$Pwd_pc" | Out-File -FilePath $Filename -Append
} else {
[System.Windows.Forms.MessageBox]::Show("Le compte $UPN est déjà présent.", "Création Administrateur" , 0, 64)
}
}
}
$Window2 = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $XML2))
$XML2.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | % {New-Variable -Name $_.Name -Value $Window2.FindName($_.Name) -Force}
$Output.text = "$(if (($SAM_dom -ne $null) -and ($Pwd_dom -ne $null)) {`"----- Admin du domaine -----`r`r$SAM_dom`r$Pwd_dom`r`r`"})$(if (($SAM_admin -ne $null)-and ($Pwd_admin -ne $null)) {`"----- Admin des serveurs -----`r`r$SAM_admin`r$Pwd_admin`r`r`"})$(if (($SAM_pc -ne $null)-and ($Pwd_pc -ne $null)) {`"----- Admin des ordinateurs -----`r`r$SAM_pc`r$Pwd_pc`r`r`"})"
$Window2.ShowDialog() | Out-Null
[System.Windows.Forms.MessageBox]::Show("Opération terminée.", "Création Administrateur" , 0, 64)
$Window2.Hide() | Out-Null
$TB_PrenomUtilisateur.Clear()
$TB_NomUtilisateur.Clear()
$TB_UPNUtilisateur.Clear()
$TB_SamAccountNameUtilisateur.Clear()
$TB_SamAccountNameUtilisateur.background = 'White'
$CB_StructureUtilisateur.Items.Clear()
$CB_AdminDomaine.IsEnabled = $false
$CB_AdminDomaine.IsChecked = $false
$CB_AdminServeurs.IsEnabled = $false
$CB_AdminServeurs.IsChecked = $false
$CB_AdminNTK.IsEnabled = $false
$CB_AdminNTK.IsChecked = $false
$CB_AdminPC.IsEnabled = $false
$CB_AdminPC.IsChecked = $false
}
})
# Action Créer Comptes Service
$BTN_AjoutCompteService.Add_Click({
if (($TB_NomService.text -eq '') -or ($TB_UPNService.text -eq '') -or ($CB_StructureService.SelectedItem -eq $null)) {
[System.Windows.Forms.MessageBox]::Show("Renseignez les champs.")
} Else {
$ADUsers = Get-ADUser -Filter * | Select SamAccountName, UserPrincipalName
$PrenomService = "Service"
$NomService = $TB_NomService.text
$Nom_StructureService = $CB_StructureService.SelectedItem
$DisplayName = "Service $NomService"
$UPN_Service = $TB_UPNService.Text
$SamAccountName_Service = $TB_SAMService.Text
$OU_Service = "OU=Services,OU=Comptes de Services,OU=$Nom_StructureService,$DN_Domain"
[int]$Pwd_Lenght = $TB_PasswordService.Text
$Pwd = Get-RandomPassword -Length $Pwd_Lenght
$Date = Get-Date -Format "dd/MM/yyyy"
if ((($ADUsers | Where {$_.SamAccountName -eq $SamAccountName_Service}).SamAccountName -ne $SamAccountName_Service ) -and (($ADUsers | Where {$_.UserPrincipalName -eq $UPN_Service}).UserPrincipalName -ne $UPN_Service)) {
New-ADUser -Name $DisplayName -GivenName $PrenomService -Surname $NomService -DisplayName $DisplayName -UserPrincipalName $UPN_Service -SamAccountName $SamAccountName_Service -Path $OU_Service -AccountNotDelegated $true -Description "Compte de service $NomService créé le $Date par $([regex]::Match((whoami /fqdn), `"CN=([^,]+),OU=`").Groups[1].Value)" -AccountPassword (ConvertTo-SecureString $Pwd -AsPlainText -Force) -Enabled $true -PasswordNeverExpires $true -CannotChangePassword $true
} else {
[System.Windows.Forms.MessageBox]::Show("Le compte $UPN est déjà présent.", "Création compte de service" , 0, 64)
}
}
$Window2 = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $XML2))
$XML2.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | % {New-Variable -Name $_.Name -Value $Window2.FindName($_.Name) -Force}
$Output.text = "$(if (($SamAccountName_Service -ne $null) -and ($Pwd -ne $null)) {`"----- Compte de service -----`r`r$SamAccountName_Service`r$Pwd`r`r`"})"
$Window2.ShowDialog() | Out-Null
[System.Windows.Forms.MessageBox]::Show("Création compte de service", "Ajout terminé." , 0, 64)
$Window2.Hide() | Out-Null
$TB_NomService.Clear()
$TB_UPNService.Clear()
$TB_SAMService.Clear()
$TB_SAMService.background = 'White'
$CB_StructureService.Items.Clear()
})
# Action Créer Comptes LDAP
$BTN_AjoutCompteLDAP.Add_Click({
if (($TB_NomLDAP.text -eq '') -or ($TB_UPNLDAP.text -eq '') -or ($CB_StructureLDAP.SelectedItem -eq $null)) {
[System.Windows.Forms.MessageBox]::Show("Renseignez les champs.")
} Else {
$ADUsers = Get-ADUser -Filter * | Select SamAccountName, UserPrincipalName
$PrenomLdap = "Ldap"
$NomLdap = $TB_NomLDAP.text
$Nom_StructureLdap = $CB_StructureLDAP.SelectedItem
$DisplayName = "Ldap $NomLdap"
$UPN_ldap = $TB_UPNLDAP.Text
$SamAccountName_ldap = $TB_SAMLDAP.Text
$OU_ldap = "OU=LDAP,OU=Comptes de Services,OU=$Nom_StructureLdap,$DN_Domain"
[int]$Pwd_Lenght = $TB_PasswordLDAP.Text
$Pwd = Get-RandomPassword -Length $Pwd_Lenght
$Date = Get-Date -Format "dd/MM/yyyy"
if ((($ADUsers | Where {$_.SamAccountName -eq $SamAccountName_ldap}).SamAccountName -ne $SamAccountName_ldap ) -and (($ADUsers | Where {$_.UserPrincipalName -eq $UPN_ldap}).UserPrincipalName -ne $UPN_ldap)) {
New-ADUser -Name $DisplayName -GivenName $PrenomLdap -Surname $NomLdap -DisplayName $DisplayName -UserPrincipalName $UPN_ldap -SamAccountName $SamAccountName_ldap -Path $OU_ldap -AccountNotDelegated $true -Description "Compte LDAP $NomLdap créé le $Date par $([regex]::Match((whoami /fqdn), `"CN=([^,]+),OU=`").Groups[1].Value)" -AccountPassword (ConvertTo-SecureString $Pwd -AsPlainText -Force) -Enabled $true -PasswordNeverExpires $true -CannotChangePassword $true -LogonWorkstations "NOHOST"
} else {
[System.Windows.Forms.MessageBox]::Show("Le compte $UPN est déjà présent.", "Création compte de ldap" , 0, 64)
}
}
$Window2 = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $XML2))
$XML2.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | % {New-Variable -Name $_.Name -Value $Window2.FindName($_.Name) -Force}
$Output.text = "$(if (($SamAccountName_ldap -ne $null) -and ($Pwd -ne $null)) {`"----- Compte LDAP -----`r`r$SamAccountName_ldap`r$Pwd`r`r`"})"
$Window2.ShowDialog() | Out-Null
[System.Windows.Forms.MessageBox]::Show("Création compte LDAP", "Ajout terminé." , 0, 64)
$Window2.Hide() | Out-Null
$TB_NomLDAP.Clear()
$TB_UPNLDAP.Clear()
$TB_SAMLDAP.Clear()
$TB_SAMLDAP.background = 'White'
$CB_StructureLDAP.Items.Clear()
})
# Gestion des événements
# Onglet Compte admin
$FormatPrenomAdmin = { $TB_PrenomUtilisateur.text = (Get-Culture).TextInfo.ToTitleCase($TB_PrenomUtilisateur.text) }
[void]$TB_PrenomUtilisateur.Add_LostKeyboardFocus({ & $FormatPrenomAdmin})
$FormatSamAccountNameUtilisateur = { $TB_SamAccountNameUtilisateur.Text = ("xxxxx." + ($TB_NomUtilisateur.text).ToLower()) -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i" }
$FormatUPNUtilisateur = { $TB_UPNUtilisateur.Text = ("xxxxx." + (($TB_NomUtilisateur.text).ToLower()) -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i") + "@" + $Suffixe_UPN}
[void]$TB_NomUtilisateur.Add_LostKeyboardFocus({ if ($TB_NomUtilisateur.Text -ne '') {& $FormatUPNUtilisateur} })
[void]$TB_NomUtilisateur.Add_LostKeyboardFocus({ if ($TB_NomUtilisateur.Text -ne '') {& $FormatSamAccountNameUtilisateur} })
$TB_SamAccountNameUtilisateur.Add_TextChanged( {
if ($TB_SamAccountNameUtilisateur.Text.Length -le 20)
{
$TB_SamAccountNameUtilisateur.background = 'LightGreen'
} else {
$TB_SamAccountNameUtilisateur.background = 'Red'
}
})
$CB_StructureUtilisateur.Add_DropDownOpened({
$CB_StructureUtilisateur.Items.Clear()
$Structure | Select -ExpandProperty Name | % { $CB_StructureUtilisateur.Items.Add($_) }
})
$CB_StructureUtilisateur.Add_SelectionChanged({
if ($CB_StructureUtilisateur.SelectedItem -eq "Global") {
$CB_AdminDomaine.IsEnabled = $true
$CB_AdminServeurs.IsEnabled = $true
$CB_AdminNTK.IsEnabled = $true
$CB_AdminPC.IsEnabled = $true
} else {
$CB_AdminDomaine.IsEnabled = $false
$CB_AdminServeurs.IsEnabled = $true
$CB_AdminNTK.IsEnabled = $true
$CB_AdminPC.IsEnabled = $true
}
})
# Onglet Compte service
$FormatSamAccountNameService = {
$Nom_StructureService = $CB_StructureService.SelectedItem
$Acronyme_StructureService = ($Structure | Where {$_.Name -eq $Nom_StructureService}).Acr_Structure
$TB_SAMService.Text = ((($Acronyme_StructureService).ToLower() + "." + ($TB_NomService.text).ToLower() + ".svc") -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i")
}
$FormatUPNService = {
$Nom_StructureService = $CB_StructureService.SelectedItem
$Acronyme_StructureService = ($Structure | Where {$_.Name -eq $Nom_StructureService}).Acr_Structure
$TB_UPNService.Text = ((($Acronyme_StructureService).ToLower() + "." + ($TB_NomService.text).ToLower() + ".svc") -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i") + "@" + $Suffixe_UPN
}
[void]$TB_NomService.Add_LostKeyboardFocus({ if (($TB_NomService.Text -ne '') -and ($CB_StructureService.SelectedItem -ne $null)) {& $FormatUPNService} })
[void]$TB_NomService.Add_LostKeyboardFocus({ if (($TB_NomService.Text -ne '') -and ($CB_StructureService.SelectedItem -ne $null)) {& $FormatSamAccountNameService} })
$CB_StructureService.Add_SelectionChanged({
if (($TB_NomService.Text -ne '') -and ($CB_StructureService.SelectedItem -ne $null)) {& $FormatUPNService;& $FormatSamAccountNameService}
})
$TB_SAMService.Add_TextChanged({
if ($TB_SAMService.Text.Length -le 20)
{
$TB_SAMService.background = 'LightGreen'
} else {
$TB_SAMService.background = 'Red'
}
})
$CB_StructureService.Add_DropDownOpened({
$CB_StructureService.Items.Clear()
$Structure | Select -ExpandProperty Name | % { $CB_StructureService.Items.Add($_) }
})
# Onglet Compte ldap
$FormatSamAccountNameLdap = {
$Nom_StructureLdap = $CB_StructureLDAP.SelectedItem
$Acronyme_StructureLdap = ($Structure | Where {$_.Name -eq $Nom_StructureLdap}).Acr_Structure
$TB_SAMLDAP.Text = ((($Acronyme_StructureLdap).ToLower() + "." + ($TB_NomLDAP.text).ToLower() + ".ldap") -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i")
}
$FormatUPNLdap = {
$Nom_StructureLdap = $CB_StructureLDAP.SelectedItem
$Acronyme_StructureLdap = ($Structure | Where {$_.Name -eq $Nom_StructureLdap}).Acr_Structure
$TB_UPNLDAP.Text = ((($Acronyme_StructureLdap).ToLower() + "." + ($TB_NomLDAP.text).ToLower() + ".ldap") -Replace "-|'| ","" -Replace "é|ê|è|ë","e" -Replace "à|â","a" -Replace "ç","c" -Replace "ï","i") + "@" + $Suffixe_UPN
}
[void]$TB_NomLDAP.Add_LostKeyboardFocus({ if (($TB_NomLDAP.Text -ne '') -and ($CB_StructureLDAP.SelectedItem -ne $null)) {& $FormatUPNLdap} })
[void]$TB_NomLDAP.Add_LostKeyboardFocus({ if (($TB_NomLDAP.Text -ne '') -and ($CB_StructureLDAP.SelectedItem -ne $null)) {& $FormatSamAccountNameLdap} })
$CB_StructureLDAP.Add_SelectionChanged({
if (($TB_NomLDAP.Text -ne '') -and ($CB_StructureLDAP.SelectedItem -ne $null)) {& $FormatUPNLdap;& $FormatSamAccountNameLdap}
})
$TB_SAMLDAP.Add_TextChanged({
if ($TB_SAMLDAP.Text.Length -le 20)
{
$TB_SAMLDAP.background = 'LightGreen'
} else {
$TB_SAMLDAP.background = 'Red'
}
})
$CB_StructureLDAP.Add_DropDownOpened({
$CB_StructureLDAP.Items.Clear()
$Structure | Select -ExpandProperty Name | % { $CB_StructureLDAP.Items.Add($_) }
})
$Window.ShowDialog() | Out-Null