79 lines
3.1 KiB
PowerShell
79 lines
3.1 KiB
PowerShell
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=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
|
|
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")
|
|
|
|
|