hello everybody and thank you for your help,
i've made this script to create new users with all details in de AD. as you can see there are a fix number of 5 groups the user can provide to add the newly created user to the provided groups. what i wan't to achieve is that the number of groups to assign the user could be variable, because some users are members of 3, some of 5 etc etc.
as i am very new to powershell i am not sure if that is even possible and would appreciate any hint into the right direction.
#New AD user creation with all details
#On the Param Part it will collect all the parameters for #the user creation by user input.
#It's meant to be done by user input, as the user who #does the job likes it like that.
param
(
[Parameter(Mandatory=$true)][String]$Vorname_Abstand_Nachname,
[Parameter(Mandatory=$true)][String]$Vorname,
[Parameter(Mandatory=$true)][String]$Initialen_Beispiel_Miguel_Santiago_MSA,
[Parameter(Mandatory=$true)][String]$Nachname,
[Parameter(Mandatory=$true)][String]$Standort,
[Parameter(Mandatory=$true)][String]$TelefonBüro,
[Parameter(Mandatory=$true)][String]$Emailadresse,
[Parameter(Mandatory=$true)][String]$Homepage,
[Parameter(Mandatory=$true)][String]$Strasse_Abstand_Hausnummer,
[Parameter(Mandatory=$true)][String]$Kantons_Kürzel,
[Parameter(Mandatory=$true)][String]$Postleitzahl,
[Parameter(Mandatory=$true)][String]$Handynummer,
[Parameter(Mandatory=$true)][String]$Job_Titel,
[Parameter(Mandatory=$true)][String]$Abteilung,
[Parameter(Mandatory=$true)][String]$Firmenname_Abstand_AG,
[Parameter(Mandatory=$true)][String]$Vorname_Punkt_Nachname,
[Parameter(Mandatory=$true)][String]$Gruppe1,
[Parameter(Mandatory=$true)][String]$Gruppe2,
[Parameter(Mandatory=$true)][String]$Gruppe3,
[Parameter(Mandatory=$true)][String]$Gruppe4,
[Parameter(Mandatory=$true)][String]$Gruppe5
)
New-ADUser
-Name "$Vorname_Abstand_Nachname"
-GivenName "$Vorname"
-Initials "$Initialen_Beispiel_Miguel_Santiago_MSA"
-Surname "$Nachname"
-DisplayName "$Vorname_Abstand_Nachname"
-Description "Login: $Vorname_Punkt_Nachname"
-Office "$Standort" -OfficePhone "$TelefonBüro"
-EmailAddress "$Emailadresse"
-HomePage "$HomePage"
-StreetAddress "$Strasse_Abstand_Hausnummer"
-City "$Standort" -State "$Kantons_kürzel"
-PostalCode "$Postleitzahl"
-UserPrincipalName "$Emailadresse"
-SamAccountName "$vorname_Punkt_Nachname"
-PasswordNeverExpires $true
-ScriptPath "genKIXTART.exe"
-HomeDirectory \\server\Users$\$vorname_Punkt_Nachname
-HomeDrive H
-MobilePhone "$Handynummer"
-Title "$Job_Titel"
-Department "$Abteilung"
-Company "$Firmenname_Abstand_AG"
-Manager "CN=Manager Name,OU=Intern,OU=Benutzer,OU=XXX,DC=xxx,DC=local"
-Path "OU=Intern,OU=Benutzer,OU=XXX,dc=xxx,dc=local"
-AccountPassword (Read-Host -AsSecureString "Gib ein Passwort an. Muss mindestens 8 Zeichen lang sein. Darf weder Vor- noch Nachnamen des Benutzers beinhalten, muss Gross- und Kleinbuchstaben als auch Zahlen und Sonderzeichen enthalten")
-Enabled $true
# This parts sets the users dial-in settings
Set-ADUser
-Identity $Vorname_Punkt_Nachname
-replace @{msNPAllowDialIn=$TRUE}
# This parts sets all the paramaeters for the country setting
Get-ADUser -SearchBase 'OU=Intern,OU=Benutzer,OU=QBIC,DC=QBIC,DC=LOCAL'
-filter * | Set-ADUser -Replace @{c="CH";co="Switzerland";countryCode="756"}
# This part adds the user to the provided groups
Add-ADPrincipalGroupMembership $Vorname_Punkt_Nachname
-MemberOf $Gruppe1,$Gruppe2,$Gruppe3,$Gruppe4
# This is the finishing part of the Script
Write-Host
-ForegroundColor Green 'All Done!'
Write-Host
-ForegroundColor Green 'Please press Enter to Exit'
Pause