ADPSScript/CreateAD.ps1

79 lines
3.1 KiB
PowerShell
Raw Normal View History

2021-10-28 10:09:08 +02:00
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)
{
2023-01-26 09:51:51 +01:00
"1" {
2021-10-28 10:09:08 +02:00
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
}
2023-01-26 09:51:51 +01:00
"2" {
2021-10-28 10:09:08 +02:00
Add-WindowsFeature AD-Domain-Services -IncludeManagementTools
}
2023-01-26 09:51:51 +01:00
"3" {
2021-10-28 10:09:08 +02:00
Write-Host -NoNewline "Enter Domainname:"
$domainname = Read-Host
Install-ADDSForest -DomainName $domainname -InstallDNS -NoRebootOnCompletion:$false
2023-01-26 09:51:51 +01:00
}
"4"{
2021-10-28 10:09:08 +02:00
New-ADOrganizationalUnit -Name "Schulung" -ProtectedFromAccidentalDeletion $False
2023-01-26 09:51:51 +01:00
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
2021-10-28 10:09:08 +02:00
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
2023-01-26 09:51:51 +01:00
}
"5" {
Import-Csv "C:\script\user.csv" -Delimiter ";" | `
2021-10-28 10:09:08 +02:00
ForEach-Object {
New-ADUser `
-Name $_.Name `
-GivenName $_.givenname `
-Surname $_.sn `
2023-01-26 09:51:51 +01:00
-Path $_.ParentOU `
2021-10-28 10:09:08 +02:00
-SamAccountName $_.samAccountName `
2023-01-26 09:51:51 +01:00
-UserPrincipalName ($_.samAccountName + "@" + $env:userdnsdomain) `
2021-10-28 10:09:08 +02:00
-AccountPassword (ConvertTo-SecureString "Start123!" -AsPlainText -Force) `
-EmailAddress $_."E-Mail Address" `
-Enabled $true `
-ChangePasswordAtLogon $true
}
2023-01-26 09:51:51 +01:00
}
2021-10-28 10:09:08 +02:00
}
2023-01-26 09:51:51 +01:00
}
until ($selection -eq "q")