In: Other
Create 3 PowerShell Scripts. The first 2 are worth 2 points each. The 3rd one is extra credit, worth 1 point.
Script 1: Add/Remove Users
Fields: Username, FirstName, LastName, Description, OUPath,
Password, Action (Add | Remove)
Script 2: Create Security Groups
Fields: Name, Description, OUPath, Scope (DomainLocal | Global |
Universal), Category (Distribution | Security)
Script 3: Modify Security Group Membership
Fields: GroupName, Username, Action (Add | Remove)
Question 1
Add User
Import-Module activedirectory
$diiffsu = Import-csv C:\test.csv
foreach ($User in $diiffsu)
{
$uname = $User.username
$paswd = $User.password
$fname = $User.firstname
$lname = $User.lastname
$OU =
$User.oupath
$description = $User.department
if (Get-ADUser -F {SamAccountName -eq $uname})
{
Write-Warning "User Already
Exist"
}
else
{
New-ADUser `
-SamAccountName $uname `
-UserPrincipalName "[email protected]" `
-Name "$fname $lname" `
-GivenName $fname `
-Surname $lname `
-Enabled $True `
-DisplayName "$lname, $fname" `
-Path $OU `
-Description $description
-AccountPassword (convertto-securestring $paswd -AsPlainText
-Force) -ChangePasswordAtLogon $True
}
}
Remove User
remove-aduser $username -confirm:$false
Question 2
New-ADGroup -Name $grpname -SamAccountName -GroupCategory $grpcat -GroupScope $grpscp -Description "Members of this group are Administrators"