„CreateAD.ps1“ ändern

This commit is contained in:
Stefan Tabbert 2023-01-26 09:51:51 +01:00
parent 2fb5503e82
commit 536807748f

View File

@ -19,7 +19,7 @@ do
$selection = Read-Host "Please make a selection"
switch ($selection)
{
'1' {
"1" {
Write-Host -NoNewline "Enter Host IP:"
$IP = Read-Host
Write-Host -NoNewline "Enter Gateway IP:"
@ -27,20 +27,21 @@ do
New-NetIPAddress -IPAddress $IP -InterfaceAlias Ethernet0 -DefaultGateway $gateway -Confirm:$false
#Set-NetIPAddress -IPAddress $IP -InterfaceAlias Ethernet0 -PrefixLength 24
}
'2' {
"2" {
Add-WindowsFeature AD-Domain-Services -IncludeManagementTools
}
'3' {
"3" {
Write-Host -NoNewline "Enter Domainname:"
$domainname = Read-Host
Install-ADDSForest -DomainName $domainname -InstallDNS -NoRebootOnCompletion:$false
}
'4' {
}
"4"{
New-ADOrganizationalUnit -Name "Schulung" -ProtectedFromAccidentalDeletion $False
New-ADOrganizationalUnit -Name "Groups" -Path "OU=Schulung,DC=schulung,DC=local" -ProtectedFromAccidentalDeletion $False
New-ADOrganizationalUnit -Name "Users" -Path "OU=Schulung,DC=schulung,DC=local" -ProtectedFromAccidentalDeletion $False
$groups = Import-Csv C:\script\groups.csv'
# Loop through the CSV
New-ADOrganizationalUnit -Name "Groups" -Path "OU=Schulung,DC=isatho,DC=me" -ProtectedFromAccidentalDeletion $False
New-ADOrganizationalUnit -Name "Users" -Path "OU=Schulung,DC=isatho,DC=me" -ProtectedFromAccidentalDeletion $False
$groups = Import-Csv "C:\script\groups.csv" `
#Loop through the CSV
foreach ($group in $groups) {
$groupProps = @{
Name = $group.name
@ -52,26 +53,27 @@ do
New-ADGroup @groupProps
} #end foreach loop
}
'5' {
Import-Csv "C:\script\user.csv" -Delimiter ';' |
}
"5" {
Import-Csv "C:\script\user.csv" -Delimiter ";" | `
ForEach-Object {
New-ADUser `
-Name $_.Name `
-GivenName $_.givenname `
-Surname $_.sn `
-Path $_."ParentOU" `
-Path $_.ParentOU `
-SamAccountName $_.samAccountName `
-UserPrincipalName ($_.samAccountName + '@' + $env:userdnsdomain) `
-UserPrincipalName ($_.samAccountName + "@" + $env:userdnsdomain) `
-AccountPassword (ConvertTo-SecureString "Start123!" -AsPlainText -Force) `
-EmailAddress $_."E-Mail Address" `
-Enabled $true `
-ChangePasswordAtLogon $true
}
}
}
}
}
until ($selection -eq 'q')
}
until ($selection -eq "q")