Labb 17: Users

Med PowerShell script, kommando New-ADUser, Microsoft Excel och en CSV-formaterad fil skapas i denna laboration ett antal användarkonto för VINET organisationen.

  1. Öppna PowerShell ISE och skriv koden nedan. Därefter sparar du scriptet som VINETusers.ps1
  2. Öppna Excel och skapa en arbetsbok med en lista på användarkonto.
    • Rubriken: FirstName, LastName, UserName, City, Country, Department, Password, Company, OU
  3. Lista av användare
    • UserName = förnamn.efternamn
    • Password = Pasajescret0#
    • Domain Context = DC=Diginto,DC=se
    • Johnry,Reyes,Chicago,USA,Executives,”OU=Vinet”
    • Martin,Klinberg,Chicago,USA,Executives,”OU=Vinet”
    • Alpha,Diallo,Chicago,USA,Executives,VINET,”OU=Management,OU=Vinet”
    • Joseph,Sanders,Stockholm,Sweden,Executives,VINET,”OU=Production,OU=Vinet”
    • Lousie,White,Stockholm,Sweden,Executives,VINET,”OU=Production,OU=Vinet”
    • David,Smith,Stockholm,Sweden,Executives,VINET,”OU=Sales,OU=Vinet”
    • Deborah,Wilson,Stockholm,Sweden,Managers,VINET,”OU=Sales,OU=Vinet”
    • Janice,Coleman,Stockholm,Sweden,Managers,VINET,”OU=Management,OU=Vinet”
    • Annie,Diaz,Stockholm,Sweden,Managers,VINET,”OU=Economy,OU=Management,OU=Vinet”
    • Ralph,Bryant,Stockholm,Sweden,Managers,VINET,”OU=Executives,OU=Management,OU=Vinet”
    • Roger,Brown,Stockholm,Sweden,Managers,VINET,”OU=Executives,OU=Management,OU=Vinet”
    • Joe,Evans,Uppsala,Sweden,Managers,VINET,”OU=HR,OU=Management,OU=Vinet”
    • Evelyn,Jones,Uppsala,Sweden,Managers,VINET,”OU=HR,OU=Management,OU=Vinet”
    • Thomas,Melander,Uppsala,Sweden,Managers,VINET,”OU=IT,OU=Management,OU=Vinet”
    • Steve,James,Uppsala,Sweden,IT Support,VINET,”OU=IT,OU=Management,OU=Vinet”
    • Johannes,Westberg,Uppsala,Sweden,IT Support,VINET,”OU=Virtual router,OU=Production,OU=Vinet”
    • Catherine,Jackson,Uppsala,Sweden,IT Support,VINET,”OU=Virtual router,OU=Production,OU=Vinet”
    • Jessica,Svensson,Uppsala,Sweden,IT Support,VINET,”OU=Virtual switch,OU=Production,OU=Vinet”
    • Donald,Rogers,Uppsala,Sweden,IT Support,VINET,”OU=Virtual switch,OU=Production,OU=Vinet”
    • Veronica,Baggio,Uppsala,Sweden,IT Support,VINET,”OU=Virtual router,OU=Production,OU=Vinet”
    • Rachel,Patterson,Uppsala,Sweden,IT Support,VINET,”OU=8210,OU=Virtual router,OU=Production,OU=Vinet”
    • Isabella,Limpar,Uppsala,Sweden,IT Support,VINET,”OU=9210,OU=Virtual router,OU=Production,OU=Vinet”
    • Nicole,Klint,Uppsala,Sweden,Administration,VINET,”OU=9210,OU=Virtual router,OU=Production,OU=Vinet”
    • Niklas,Andersson,Karlstad,Sweden,Administration,VINET,”OU=2950,OU=Virtual switch,OU=Production,OU=Vinet”
    • Judy,Miller,Karlstad,Sweden,Administration,VINET,”OU=2950,OU=Virtual switch,OU=Production,OU=Vinet”
    • Adam,Ahlstedt,Karlstad,Sweden,Administration,VINET,”OU=3920,OU=Virtual switch,OU=Production,OU=Vinet”
    • Jean,Henderson,Karlstad,Sweden,Production,VINET,”OU=3920,OU=Virtual switch,OU=Production,OU=Vinet”
    • Wilma,Andersdotter,Stockholm,Sweden,Production,VINET,”OU=Clients,OU=Sales,OU=Vinet”
    • Katya,Morgan,Chicago,USA,Production,VINET,”OU=Clients,OU=Sales,OU=Vinet”
    • Patrik,Olson,Chicago,USA,Production,VINET,”OU=Development,OU=Sales,OU=Vinet”
    • Erik,Hansson,Chicago,USA,Production,VINET,”OU=Marketing,OU=Sales,OU=Vinet”
    • Ali,Raz,Chicago,USA,Production,VINET,”OU=Partners,OU=Sales,OU=Vinet”
    • Bruce,Barnes,Chicago,USA,Production,VINET,”OU=Partners,OU=Sales,OU=Vinet”
    • Viktor,Ericson,Chicago,USA,Production,VINET,”OU=Partners,OU=Sales,OU=Vinet”
    • Stefan,Nygren,Chicago,USA,Production,VINET,”OU=Partners,OU=Sales,OU=Vinet”

# Create user accounts for VINET
# Name for the script: VINETusers.ps1
# Chalo reyes, 2019-08-01
#
Import-Module ActiveDirectory
#
# Import active directory module for running AD cmdlets
Import-Module activedirectory

#Store the data from ADUsers.csv in the $ADUsers variable
$ADUsers = Import-csv C:\Scripts\ADPS\VINETusers.csv

#Loop through each row containing user details in the CSV file
foreach ($User in $ADUsers)
{
#Read user data from each field in each row and assign the data to a variable as below

$Username = $User.username
$Password = $User.password
$Firstname = $User.firstname
$Lastname = $User.lastname
$OU = $User.ou #This field refers to the OU the user account is to be created in
$city = $User.city
$country = $User.country
$company = $User.company
$department = $User.department
$Password = $User.Password

#Check to see if the user already exists in AD
if (Get-ADUser -F {SamAccountName -eq $Username})
{
#If user does exist, give a warning
Write-Warning ”A user account with username $Username already exist in Active Directory.”
}
else
{
#User does not exist then proceed to create the new user account

#Account will be created in the OU provided by the $OU variable read from the CSV file
New-ADUser `
-SamAccountName $Username `
-UserPrincipalName ”$Username@diginto.local” `
-Name ”$Firstname $Lastname” `
-GivenName $Firstname `
-Surname $Lastname `
-Enabled $True `
-DisplayName ”$Lastname, $Firstname” `
-Path $OU `
-City $city `
-Company $company `
-Department $department `
-AccountPassword (convertto-securestring $Password -AsPlainText -Force) -ChangePasswordAtLogon $True
}

}