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