Hey Guys,
I wanted to thank Paul for getting me started in IT, Powershell ftw.
what your guys feedback on this script
# Import required modules
Import-Module ActiveDirectory
# Prompt user for CSV file path
$filepath = "C:\ps1\newusers1.csv"
# Import File to variable
$users = Import-Csv $filepath
# Loop through each row and gather information
ForEach ($user in $users) {
# Gather the user's information
$uname = $users.UserPrincipalName
$name = $user.Name
$givenname = $user.GivenName
$surname = $user.Surname
$dname = $user.Displayname
$saccount = $user.SamAccountname
$office = $user.Office
$department = $user.Department
$manager = $user.Manager
$job = $user.Title
$company = $user.Company
$address = $user.StreetAddress
$city = $user.City
$state = $user.State
$postal = $user.Postalcode
$country = $user.Country
$ou = $user.'Organizational Unit'
# Ad Attributes
$Attributes = @{
Enabled = $true
ChangePasswordAtLogon = $true
AccountPassword = "totalsecurepassword1234" | ConvertTo-SecureString -AsPlainText -Force
Path = $ou
UserPrincipalName = $uname
Name = $name
GivenName = $givenname
Surname = $surname
DisplayName = $dname
SamAccountname = $saccount
Office = $office
Department = $department
Manager = $manager
Title = $job
Company = $company
StreetAddress = $address
City = $city
State = $state
Postalcode = $postal
Country = $country
}
# Create new AD user for each user in CSV file
New-ADUser @Attributes
# Echo output for each new User
echo "Account has been created for $dname in $ou"
}
That’s my first script with CSV import.