From 2b363f156447dcff2fd9fb95572cbd8a168dc669 Mon Sep 17 00:00:00 2001 From: Stefan Tabbert Date: Thu, 28 Oct 2021 10:09:08 +0200 Subject: [PATCH] createAD.ps1 --- CreateAD.ps1 | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 CreateAD.ps1 diff --git a/CreateAD.ps1 b/CreateAD.ps1 new file mode 100644 index 0000000..755acf6 --- /dev/null +++ b/CreateAD.ps1 @@ -0,0 +1,77 @@ +function Show-Menu +{ + param ( + [string]$Title = 'Network and Active Directory Setup' + ) + Clear-Host + Write-Host -BackgroundColor Gray -ForegroundColor Blue "================ $Title ================" + + Write-Host "1: Network Setup" + Write-Host "2: Install AD Feature and Domain Services." + Write-Host "3: Install AD Forest and DNS." + Write-Host "4: Add Groups" + Write-Host "5: Add Users" + Write-Host "Q: Press 'Q' to quit." +} +do + { + Show-Menu + $selection = Read-Host "Please make a selection" + switch ($selection) + { + '1' { + Write-Host -NoNewline "Enter Host IP:" + $IP = Read-Host + Write-Host -NoNewline "Enter Gateway IP:" + $gateway = Read-Host + New-NetIPAddress -IPAddress $IP -InterfaceAlias Ethernet0 -DefaultGateway $gateway -Confirm:$false + #Set-NetIPAddress -IPAddress $IP -InterfaceAlias Ethernet0 -PrefixLength 24 + } + '2' { + Add-WindowsFeature AD-Domain-Services -IncludeManagementTools + } + '3' { + Write-Host -NoNewline "Enter Domainname:" + $domainname = Read-Host + Install-ADDSForest -DomainName $domainname -InstallDNS -NoRebootOnCompletion:$false + } + '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 + foreach ($group in $groups) { + $groupProps = @{ + Name = $group.name + Path = $group.path + GroupScope = $group.scope + GroupCategory = $group.category + Description = $group.description + }#end groupProps + New-ADGroup @groupProps + + } #end foreach loop + } + '5' { + Import-Csv "C:\script\user.csv" -Delimiter ';' | + + ForEach-Object { + New-ADUser ` + -Name $_.Name ` + -GivenName $_.givenname ` + -Surname $_.sn ` + -Path $_."ParentOU" ` + -SamAccountName $_.samAccountName ` + -UserPrincipalName ($_.samAccountName + '@' + $env:userdnsdomain) ` + -AccountPassword (ConvertTo-SecureString "Start123!" -AsPlainText -Force) ` + -EmailAddress $_."E-Mail Address" ` + -Enabled $true ` + -ChangePasswordAtLogon $true + } + } + + } + + } + until ($selection -eq 'q') \ No newline at end of file