Compare commits
10 Commits
4d93929e02
...
c4d521fe36
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4d521fe36 | ||
|
|
13e696ef1b | ||
|
|
cf628d9903 | ||
|
|
a2ca35f457 | ||
|
|
4d81adfc73 | ||
|
|
f3a71ea740 | ||
|
|
4e2007e54a | ||
|
|
55884794ef | ||
|
|
30847a0e30 | ||
|
|
adf01ced5f |
182
AutomateCreateNewUsers.ps1
Normal file
182
AutomateCreateNewUsers.ps1
Normal file
@ -0,0 +1,182 @@
|
||||
#Import logon scripts for all departments from the CSV file.
|
||||
$logonScripts = Import-Csv -Path "D:\Scripts\Data\LogonScript.csv"
|
||||
|
||||
#Import users from CSV file.
|
||||
$creationDate = (Get-Date).ToString("yyyy-MM-dd")
|
||||
$basePath = "D:\Departments\Human Resources\UserManagement\"
|
||||
$newuserPath = $basePath + "NewUsers.csv"
|
||||
$provisionedPath = $basePath + "Completed\ProvisionedUsers.csv"
|
||||
$currentuserPath = $basePath + "Completed\CurrentUsers.csv"
|
||||
|
||||
$newfile = Test-Path $newuserPath
|
||||
|
||||
if($newfile){
|
||||
$users = Import-Csv -Path $newuserPath
|
||||
|
||||
$defphone = "713-485-5555" #Default phone number
|
||||
$homeFolder = "\\chipvfs01\Users\" #Path to Users shared folder which is to store user home folders
|
||||
$userAccounts = @() #UserAccounts object to store user account information
|
||||
|
||||
foreach($user in $users){ #Loop through each user read from the NewUsers.csv file
|
||||
|
||||
#Read users information from the CSV file
|
||||
$gname = $user.FirstName
|
||||
$mname = $user.MiddleName
|
||||
$sname = $user.LastName
|
||||
$fullname = $gname + " " + $sname
|
||||
$description = $user.Description
|
||||
$office = $user.Office
|
||||
$country = $user.Country
|
||||
$company = "ITLifeSkills"
|
||||
$title = $user.JobTitle
|
||||
$department = $user.Department
|
||||
|
||||
#Get the LogOnScript for the department of the current user
|
||||
$script = ($logonScripts | where {$_.Department -eq $department}).LogonScript
|
||||
|
||||
#Use the phone number in the CSV file if found otherwise use the default phone number
|
||||
if($user.PhoneNumber){
|
||||
|
||||
$phone = $user.PhoneNumber
|
||||
|
||||
}
|
||||
else{
|
||||
$phone = $defphone
|
||||
}
|
||||
|
||||
# Generate a random password using ascii-characters-from-33-126
|
||||
# For more information about the asciicharacters https://www.ibm.com/docs/en/sdse/6.4.0?topic=configuration-ascii-characters-from-33-126
|
||||
|
||||
$password = -join([char[]](33..122) | Get-Random -Count 10)
|
||||
$securePassword = ConvertTo-SecureString ($password) -AsPlainText -Force
|
||||
|
||||
#Construct the username samAccount from middle name, given name and surname.
|
||||
if($user.MiddleName){
|
||||
|
||||
$samAccount = ($gname[0] + $mname[0] + $sname[0]).ToLower()
|
||||
|
||||
}
|
||||
else{
|
||||
$samAccount = ($gname[0] + "x" + $sname[0]).ToLower()
|
||||
|
||||
}
|
||||
|
||||
# Verify if the username exists, if Yes add $i to the username
|
||||
$i = 1
|
||||
do{
|
||||
|
||||
try{
|
||||
$exist = Get-ADUser -Identity $samAccount
|
||||
$samAccount = $samAccount + $i
|
||||
$i++
|
||||
}
|
||||
catch{
|
||||
|
||||
break
|
||||
|
||||
}
|
||||
}while($exist)
|
||||
|
||||
$userprincipal = $samAccount + "@hq.itlifeskills.local"
|
||||
|
||||
#If found the manager in the CSV file, get the distinguished name of the manager
|
||||
$manager = $user.Manager
|
||||
if($manager){
|
||||
$userManager = (Get-ADUser -Filter 'DisplayName -eq $manager').DistinguishedName
|
||||
}
|
||||
else{
|
||||
$userManager = $null
|
||||
}
|
||||
|
||||
#Find the Distinguished name of the department OU
|
||||
$baseOU = "OU=Users,OU=ITLifeSkills,DC=hq,DC=itlifeskills,DC=local"
|
||||
$OU = (Get-ADOrganizationalUnit -SearchBase $baseOU -Filter 'Name -eq $department').DistinguishedName
|
||||
|
||||
#Path to the User Home Folder
|
||||
$userFolder = $homeFolder + $fullname
|
||||
|
||||
#Form the object of user properties
|
||||
$userProperties = @{
|
||||
GivenName = $gname
|
||||
Surname = $sname
|
||||
DisplayName = $fullname
|
||||
Name = $fullname
|
||||
SamAccountName = $samAccount
|
||||
AccountPassword = $securePassword
|
||||
UserPrincipalName = $userprincipal
|
||||
Office = $office
|
||||
Company = $company
|
||||
Country = $country
|
||||
Department = $department
|
||||
Description = $description
|
||||
Title = $title
|
||||
OfficePhone = $phone
|
||||
HomeDirectory = $userFolder
|
||||
HomeDrive = "U:"
|
||||
ScriptPath = $script
|
||||
Path = $OU
|
||||
Manager = $userManager
|
||||
ChangePasswordAtLogon = $true
|
||||
Enabled = $true
|
||||
}
|
||||
|
||||
#Create the new user from the @userProperties object
|
||||
New-ADUser @userProperties
|
||||
|
||||
#Chek if the folder exists. If not, create the user home folder
|
||||
$exist = Test-Path $userFolder
|
||||
|
||||
if(!$exist){
|
||||
|
||||
New-Item -Path $userFolder -ItemType "Directory"
|
||||
}
|
||||
|
||||
#Get the current access list on the user home folder
|
||||
$aclList = Get-Acl -Path $userFolder
|
||||
|
||||
#Create a rule parameters object for to grant FullControl access for the current user
|
||||
|
||||
$parameters = @(
|
||||
"HQ\$samAccount" #IdentityReference
|
||||
"FullControl" #FileSystemRights
|
||||
,@( #InheritanceFlags
|
||||
"ContainerInherit" #Apply to the current folder
|
||||
"ObjectInherit" #Apply to subfolders and files in the current folder
|
||||
)
|
||||
"None" #PropagationFlags
|
||||
"Allow" #AccessControlType
|
||||
)
|
||||
|
||||
#Create the rule from the paramters
|
||||
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $parameters
|
||||
|
||||
#Add the rule into the current access list
|
||||
$aclList.AddAccessRule($rule)
|
||||
|
||||
#Set the new rule on the user home folder
|
||||
$aclList | Set-Acl $userFolder
|
||||
|
||||
#Appends the current user to the ProvisionedUsers.csv file
|
||||
$user | Export-Csv -Path $provisionedPath -Append -NoTypeInformation
|
||||
|
||||
#Build the userdata object to export
|
||||
|
||||
$user | Add-Member -MemberType NoteProperty -Name "CreatedOn" -Value $creationDate
|
||||
$user | Add-Member -MemberType NoteProperty -Name "SamAccountName" -Value $samAccount
|
||||
$user | Add-Member -MemberType NoteProperty -Name "AccountPassword" -Value $password
|
||||
$user | Add-Member -MemberType NoteProperty -Name "Status" -Value "New"
|
||||
$user | Add-Member -MemberType NoteProperty -Name "BadgeNumber" -Value ""
|
||||
$user | Add-Member -MemberType NoteProperty -Name "AssignedSeat" -Value ""
|
||||
$user | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value ""
|
||||
|
||||
$userAccounts += $user
|
||||
|
||||
}
|
||||
|
||||
#After that, delete the NewUsers.csv file
|
||||
Remove-Item -Path $newuserPath
|
||||
|
||||
#Appends new user account information to CurrentUsers.csv
|
||||
$userAccounts | Export-Csv -Path $currentuserPath -Append -NoTypeInformation
|
||||
|
||||
}
|
||||
27
CreateDFSFolders.ps1
Normal file
27
CreateDFSFolders.ps1
Normal file
@ -0,0 +1,27 @@
|
||||
#Path to the Projects folder in namespace root.
|
||||
$path = "\\hq\CorporateData\Projects\"
|
||||
|
||||
#Path to the targets where actual data is stored
|
||||
$targetpaths = "\\CHIPVFS01\Projects\", "\\CHIPVFS02\Projects\"
|
||||
|
||||
#Loop through each target path
|
||||
foreach($targetpath in $targetpaths){
|
||||
|
||||
#Get all the subfolders in the target path
|
||||
$folders= Get-ChildItem -Path $targetpath
|
||||
|
||||
#Loop through each subfolder
|
||||
foreach($folder in $folders){
|
||||
|
||||
#Construct the full path for the folder target
|
||||
$folderpath = $path + $folder
|
||||
|
||||
#Construct the full path for the target
|
||||
$foldertargetpath = $targetpath + $folder
|
||||
|
||||
#Create the folder with target
|
||||
New-DfsnFolder -Path $folderpath -TargetPath $foldertargetpath
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
172
CreateNewUsers.ps1
Normal file
172
CreateNewUsers.ps1
Normal file
@ -0,0 +1,172 @@
|
||||
#Import logon scripts for all departments from the CSV file.
|
||||
$logonScripts = Import-Csv -Path "C:\Scripts\Data\LogonScript.csv"
|
||||
|
||||
#Import user Angel Stewart from CSV file.
|
||||
$users = Import-Csv -Path "C:\Scripts\Data\NewUsers.csv" | where {$_.FirstName -eq "Angel" -and $_.LastName -eq "Stewart"}
|
||||
|
||||
$defphone = "713-485-5555" #Default phone number
|
||||
$homeFolder = "\\chipvfs01\Users\" #Path to Users shared folder which is to store user home folders
|
||||
$userAccounts = @() #UserAccounts object to store user account information
|
||||
|
||||
foreach($user in $users){ #Loop through each user read from the NewUsers.csv file
|
||||
|
||||
#Read users information from the CSV file
|
||||
$gname = $user.FirstName
|
||||
$mname = $user.MiddleName
|
||||
$sname = $user.LastName
|
||||
$fullname = $gname + " " + $sname
|
||||
$description = $user.Description
|
||||
$office = $user.Office
|
||||
$country = $user.Country
|
||||
$company = "ITLifeSkills"
|
||||
$title = $user.JobTitle
|
||||
$department = $user.Department
|
||||
|
||||
#Get the LogOnScript for the department of the current user
|
||||
$script = ($logonScripts | where {$_.Department -eq $department}).LogonScript
|
||||
|
||||
#Use the phone number in the CSV file if found otherwise use the default phone number
|
||||
if($user.PhoneNumber){
|
||||
|
||||
$phone = $user.PhoneNumber
|
||||
|
||||
}
|
||||
else{
|
||||
$phone = $defphone
|
||||
}
|
||||
|
||||
# Generate a random password using ascii-characters-from-33-126
|
||||
# For more information about the asciicharacters https://www.ibm.com/docs/en/sdse/6.4.0?topic=configuration-ascii-characters-from-33-126
|
||||
|
||||
$password = -join([char[]](33..122) | Get-Random -Count 10)
|
||||
$securePassword = ConvertTo-SecureString ($password) -AsPlainText -Force
|
||||
|
||||
#Construct the username samAccount from middle name, given name and surname.
|
||||
if($user.MiddleName){
|
||||
|
||||
$samAccount = ($gname[0] + $mname[0] + $sname[0]).ToLower()
|
||||
|
||||
}
|
||||
else{
|
||||
$samAccount = ($gname[0] + "x" + $sname[0]).ToLower()
|
||||
|
||||
}
|
||||
|
||||
# Verify if the username exists, if Yes add $i to the username
|
||||
$i = 1
|
||||
do{
|
||||
|
||||
try{
|
||||
$exist = Get-ADUser -Identity $samAccount
|
||||
$samAccount = $samAccount + $i
|
||||
$i++
|
||||
}
|
||||
catch{
|
||||
|
||||
break
|
||||
|
||||
}
|
||||
}while($exist)
|
||||
|
||||
$userprincipal = $samAccount + "@hq.itlifeskills.local"
|
||||
|
||||
#If found the manager in the CSV file, get the distinguished name of the manager
|
||||
$manager = $user.Manager
|
||||
if($manager){
|
||||
$userManager = (Get-ADUser -Filter 'DisplayName -eq $manager').DistinguishedName
|
||||
}
|
||||
else{
|
||||
$userManager = $null
|
||||
}
|
||||
|
||||
#Find the Distinguished name of the department OU
|
||||
$baseOU = "OU=Users,OU=ITLifeSkills,DC=hq,DC=itlifeskills,DC=local"
|
||||
$OU = (Get-ADOrganizationalUnit -SearchBase $baseOU -Filter 'Name -eq $department').DistinguishedName
|
||||
|
||||
#Path to the User Home Folder
|
||||
$userFolder = $homeFolder + $fullname
|
||||
|
||||
#Form the object of user properties
|
||||
$userProperties = @{
|
||||
GivenName = $gname
|
||||
Surname = $sname
|
||||
DisplayName = $fullname
|
||||
Name = $fullname
|
||||
SamAccountName = $samAccount
|
||||
AccountPassword = $securePassword
|
||||
UserPrincipalName = $userprincipal
|
||||
Office = $office
|
||||
Company = $company
|
||||
Country = $country
|
||||
Department = $department
|
||||
Description = $description
|
||||
Title = $title
|
||||
OfficePhone = $phone
|
||||
HomeDirectory = $userFolder
|
||||
HomeDrive = "U:"
|
||||
ScriptPath = $script
|
||||
Path = $OU
|
||||
Manager = $userManager
|
||||
ChangePasswordAtLogon = $true
|
||||
Enabled = $true
|
||||
}
|
||||
|
||||
#Create the new user from the @userProperties object
|
||||
New-ADUser @userProperties
|
||||
|
||||
#Chek if the folder exists. If not, create the user home folder
|
||||
$exist = Test-Path $userFolder
|
||||
|
||||
if(!$exist){
|
||||
|
||||
New-Item -Path $userFolder -ItemType "Directory"
|
||||
}
|
||||
|
||||
#Get the current access list on the user home folder
|
||||
$aclList = Get-Acl -Path $userFolder
|
||||
|
||||
#Create a rule parameters object for to grant FullControl access for the current user
|
||||
|
||||
$parameters = @(
|
||||
"HQ\$samAccount" #IdentityReference
|
||||
"FullControl" #FileSystemRights
|
||||
,@( #InheritanceFlags
|
||||
"ContainerInherit" #Apply to the current folder
|
||||
"ObjectInherit" #Apply to subfolders and files in the current folder
|
||||
)
|
||||
"None" #PropagationFlags
|
||||
"Allow" #AccessControlType
|
||||
)
|
||||
|
||||
#Create the rule from the paramters
|
||||
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $parameters
|
||||
|
||||
#Add the rule into the current access list
|
||||
$aclList.AddAccessRule($rule)
|
||||
|
||||
#Set the new rule on the user home folder
|
||||
$aclList | Set-Acl $userFolder
|
||||
|
||||
#Build the userdata object to export
|
||||
|
||||
$userData = [PSCustomObject]@{
|
||||
Name = $fullname;
|
||||
SamAccountName = $samAccount;
|
||||
AccountPassword = $password;
|
||||
Office = $office;
|
||||
Company = $company;
|
||||
Country = $country
|
||||
Department = $department;
|
||||
Description = $description;
|
||||
Title = $title;
|
||||
OfficePhone = $phone;
|
||||
Manager = $manager
|
||||
}
|
||||
|
||||
$userAccounts += $userData
|
||||
|
||||
}
|
||||
|
||||
|
||||
$userAccounts | Export-Csv -Path "C:\Scripts\Data\UserAccounts.csv" -NoTypeInformation
|
||||
#Get-ADUser -Identity egh -Properties *
|
||||
7
CreateOrganizationalUnits.ps1
Normal file
7
CreateOrganizationalUnits.ps1
Normal file
@ -0,0 +1,7 @@
|
||||
$departments = (Import-Csv -Path "C:\Scripts\Data\Departments.csv").Department
|
||||
|
||||
foreach ($department in $departments){
|
||||
|
||||
New-ADOrganizationalUnit -Name $department -Path "OU=Users,OU=ITLifeSkills,DC=hq,DC=itlifeskills,DC=local"
|
||||
}
|
||||
|
||||
7
Createnewdepartment.ps1
Normal file
7
Createnewdepartment.ps1
Normal file
@ -0,0 +1,7 @@
|
||||
$departments = (Import-Csv -Path "C:\Scripts\Data\Departments.csv").Department
|
||||
|
||||
foreach ($department in $departments){
|
||||
|
||||
New-Item -Path "D:\Departments" -Name $department -ItemType "directory"
|
||||
}
|
||||
|
||||
55
Createnewgroups.ps1
Normal file
55
Createnewgroups.ps1
Normal file
@ -0,0 +1,55 @@
|
||||
$department = "Art and Design"
|
||||
$name = $department.Split(" ")
|
||||
$groupName= "grp"
|
||||
foreach($word in $name){
|
||||
|
||||
if($word -ne "and"){
|
||||
|
||||
$groupName = $groupName + "-" + ($word).ToLower()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$departments = (Import-Csv -Path "C:\Scripts\Data\Departments.csv").Department
|
||||
|
||||
$path = "OU=Groups,OU=ITLifeSkills,DC=hq,DC=itlifeskills,DC=local"
|
||||
|
||||
foreach ($department in $departments){
|
||||
|
||||
$name = $department.Split(" ")
|
||||
$groupName= "grp"
|
||||
foreach($word in $name){
|
||||
|
||||
if($word -ne "and"){
|
||||
|
||||
$groupName = $groupName + "-" + ($word).ToLower()
|
||||
}
|
||||
}
|
||||
|
||||
New-ADGroup -Name $groupName -SamAccountName $groupName -GroupCategory Security -GroupScope Global -DisplayName $groupName -Path $path -Description $department
|
||||
}
|
||||
|
||||
|
||||
|
||||
$projects = (Import-Csv -Path "C:\Scripts\Data\Projects.csv").Project
|
||||
|
||||
$path = "OU=Groups,OU=ITLifeSkills,DC=hq,DC=itlifeskills,DC=local"
|
||||
|
||||
foreach ($project in $projects){
|
||||
|
||||
$name = $project.Split(" ")
|
||||
$groupName= "grp"
|
||||
foreach($word in $name){
|
||||
|
||||
if($word -ne "and"){
|
||||
|
||||
$groupName = $groupName + "-" + ($word).ToLower()
|
||||
}
|
||||
}
|
||||
|
||||
New-ADGroup -Name $groupName -SamAccountName $groupName -GroupCategory Security -GroupScope Global -DisplayName $groupName -Path $path -Description $project
|
||||
}
|
||||
|
||||
|
||||
|
||||
7
Createnewproject.ps1
Normal file
7
Createnewproject.ps1
Normal file
@ -0,0 +1,7 @@
|
||||
$projects = (Import-Csv -Path "C:\Scripts\Data\Projects.csv").Project
|
||||
|
||||
foreach ($project in $projects){
|
||||
|
||||
New-Item -Path "D:\Projects" -Name $project -ItemType "directory"
|
||||
}
|
||||
|
||||
99
CurrentUsers.csv
Normal file
99
CurrentUsers.csv
Normal file
@ -0,0 +1,99 @@
|
||||
"GivenName","MiddleName","Surname","Description","Office","OfficePhone","Country","Department","Title","Manager","CreatedOn","SamAccountName","AccountPassword","Status","BadgeNumber","AssignedSeat","ComputerName"
|
||||
"Pamela","Kristen","Srini","10/30/2024","Aurora","713-485-5574","US","Humance Resources","HR Specialist ","Ryan Brown","11/9/2024","pks","Set","Completed","1000000","B101Seat1","BJSHFG72"
|
||||
"Cameron","Ashley","Rodriguez","10/30/2019","Aurora","713-485-5557","US","Accounting and Finance","Accountant","Edward Hernandez","11/16/2024","car","Set","Completed","1000001","B101Seat2","BJSHFG73"
|
||||
"Peter","Ronald","Nara","11/20/2014","Aurora","713-485-5558","US","Accounting and Finance","Accountant","Edward Hernandez","11/23/2024","prn","Set","Completed","1000002","B101Seat3","BJSHFG74"
|
||||
"Theodore","Jon","Diaz","11/20/2014","Aurora","713-485-5559","US","Accounting and Finance","Accountant","Edward Hernandez","11/23/2024","tjd","Set","Completed","1000003","B101Seat4","BJSHFG75"
|
||||
"Christine","Ruth","Nara","11/20/2014","Aurora","713-485-5560","US","Art and Design","Art and Design Manager","Ryan Brown","11/23/2024","crn","Set","Completed","1000004","B101Seat5","BJSHFG76"
|
||||
"Latoya","Jamie","Shen","11/20/2014","Aurora","713-485-5561","US","Art and Design","UX design","Christine Nara","11/23/2024","ljs","Set","Completed","1000005","B101Seat6","BJSHFG77"
|
||||
"Stephanie","Angela","Cox","11/20/2014","Aurora","713-485-5562","US","Art and Design","UX design","Christine Nara","11/23/2024","sac","Set","Completed","1000006","B101Seat7","BJSHFG78"
|
||||
"Joshua","Hunter","Lee","11/20/2014","Aurora","713-485-5563","US","Art and Design","Backend UI design","Christine Nara","11/23/2024","jhl","Set","Completed","1000007","B101Seat8","BJSHFG79"
|
||||
"Dalton","","Wood","11/20/2014","Aurora","713-485-5564","US","Art and Design","Animation design","Christine Nara","11/23/2024","dxw","Set","Completed","1000008","B101Seat9","BJSHFG80"
|
||||
"Clayton","Sarah","Shan","11/20/2014","Aurora","713-485-5565","US","Content and Review ","Content and Review Manager","Ryan Brown","11/23/2024","css","Set","Completed","1000009","B101Seat10","BJSHFG81"
|
||||
"Paige","Mason","Peterson","11/20/2014","Aurora","713-485-5566","US","Content and Review","Content creator","Clayton Shan","11/23/2024","pmp","Set","Completed","1000010","B101Seat11","BJSHFG82"
|
||||
"Dalton","Jeremiah","Hill","11/20/2014","Aurora","713-485-5567","US","Content and Review","Content creator","Clayton Shan","11/23/2024","djh","Set","Completed","1000011","B101Seat12","BJSHFG83"
|
||||
"Johnathan","","Srini","11/20/2014","Aurora","713-485-5568","US","Content and Review","Content creator","Clayton Shan","11/23/2024","jxs","Set","Completed","1000012","B101Seat13","BJSHFG84"
|
||||
"Beth","Willie","Ruiz","11/20/2014","Aurora","713-485-5569","US","Content and Review","Content creator","Clayton Shan","11/23/2024","bwr","Set","Completed","1000013","B101Seat14","BJSHFG85"
|
||||
"Rachel","Robert","Davis","11/20/2014","Aurora","713-485-5570","US","Content and Review","Content creator","Clayton Shan","11/23/2024","rrd","Set","Completed","1000014","B101Seat15","BJSHFG86"
|
||||
"Dustin","Rebecca","Nath","11/20/2014","Aurora","713-485-5571","US","Content and Review","Content creator","Clayton Shan","11/23/2024","drn","Set","Completed","1000015","B101Seat16","BJSHFG87"
|
||||
"Chloe","","Reed","11/20/2014","Aurora","713-485-5572","US","Content and Review","Content editor","Clayton Shan","11/23/2024","cxr","Set","Completed","1000016","B101Seat17","BJSHFG88"
|
||||
"Devin","","Hernandez","11/20/2014","Aurora","713-485-5575","US","Humance Resources","HR Specialist ","Ryan Brown","11/23/2024","dxh","Set","Completed","1000017","B101Seat18","BJSHFG89"
|
||||
"Jerry","Heidi","Shen","11/20/2014","Aurora","713-485-5576","US","Humance Resources","HR Specialist ","Ryan Brown","11/23/2024","jhs","Set","Completed","1000018","B101Seat19","BJSHFG90"
|
||||
"Wayne","Kelvin","Chande","11/20/2014","Aurora","713-485-5577","US","Humance Resources","HR Specialist ","Ryan Brown","11/23/2024","wkc","Set","Completed","1000019","B101Seat20","BJSHFG91"
|
||||
"Katelyn","Destiny","Adams","11/20/2014","Aurora","713-485-5578","US","Information Technology","Service Desk Manager","Ryan Brown","11/23/2024","kda","Set","Completed","1000020","B101Seat21","BJSHFG92"
|
||||
"Cassie","Jasmine","Kennedy","11/20/2014","Aurora","713-485-5579","US","Information Technology","Service Desk","Katelyn Adams","11/23/2024","cjk","Set","Completed","1000021","B101Seat22","BJSHFG93"
|
||||
"Kimberly","","Kelly","11/20/2014","Elgine","713-485-5580","US","Information Technology","Service Desk","Katelyn Adams","11/23/2024","kxk","Set","Completed","1000022","B101Seat23","BJSHFG94"
|
||||
"Madeline","Destiny","Phillips","11/20/2014","Aurora","713-485-5581","US","Marketing","Social Media Manager","Ryan Brown","11/23/2024","mdp","Set","Completed","1000023","B101Seat24","BJSHFG95"
|
||||
"Kristy","Victoria","Hernandez","11/20/2014","Aurora","713-485-5582","US","Marketing","Marketing Professional","Madeline Phillips","11/23/2024","kvh","Set","Completed","1000024","B101Seat25","BJSHFG96"
|
||||
"Ashley","Jennifer","Wood","11/20/2014","Aurora","713-485-5583","US","Marketing","Content Markerting Specialist","Madeline Phillips","11/23/2024","ajw","Set","Completed","1000025","B101Seat26","BJSHFG97"
|
||||
"Donald","Aaron","McDonald","11/20/2014","Aurora","713-485-5584","US","Marketing","Markerting Assistant ","Madeline Phillips","11/23/2024","dam","Set","Completed","1000026","B101Seat27","BJSHFG98"
|
||||
"Kristopher","","Kapoor","11/20/2014","Elgine","713-485-5586","US","Operations","Operation Manager","Ryan Brown","11/23/2024","kxk1","Set","Completed","1000027","B101Seat28","BJSHFG99"
|
||||
"Alex","Edgar","Allen","11/20/2014","Elgine","713-485-5587","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","aea","Set","Completed","1000028","B101Seat29","BJSHFG100"
|
||||
"Sara","Melanie","Young","11/20/2014","Elgine","713-485-5588","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","smy","Set","Completed","1000029","B101Seat30","BJSHFG101"
|
||||
"Brent","Eddie","Wang","11/20/2014","Elgine","713-485-5589","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","bew","Set","Completed","1000030","B101Seat31","BJSHFG102"
|
||||
"Karl","","Xie","11/20/2014","Elgine","713-485-5590","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","kxx","Set","Completed","1000031","B101Seat32","BJSHFG103"
|
||||
"Lee","Kaitlyn","Romero","11/20/2014","Elgine","713-485-5591","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","lkr","Set","Completed","1000032","B101Seat33","BJSHFG104"
|
||||
"Joseph","","Smith","11/20/2014","Elgine","713-485-5592","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","jxs1","Set","Completed","1000033","B101Seat34","BJSHFG105"
|
||||
"Luis","Holly","Hall","11/20/2014","Elgine","713-485-5593","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","lhh","Set","Completed","1000034","B101Seat35","BJSHFG106"
|
||||
"Colleen","Bradley","Lin","11/20/2014","Elgine","713-485-5594","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","cbl","Set","Completed","1000035","B101Seat36","BJSHFG107"
|
||||
"Darryl","","He","11/20/2014","Elgine","713-485-5595","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","dxh","Set","Completed","1000036","B101Seat37","BJSHFG108"
|
||||
"Alexis","Misty","Flores","11/20/2014","Elgine","713-485-5596","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","amf","Set","Completed","1000037","B101Seat38","BJSHFG109"
|
||||
"Renee","Autumn","Gill","11/20/2014","Elgine","713-485-5597","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","rag","Set","Completed","1000038","B101Seat39","BJSHFG110"
|
||||
"Bianca","","Hu","11/20/2014","Elgine","713-485-5598","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","bxh","Set","Completed","1000039","B101Seat40","BJSHFG111"
|
||||
"Abigail","Jared","Peterson","11/20/2014","Elgine","713-485-5599","US","Operations","Sr. Operation specialist","Kristopher Kapoor","11/23/2024","ajp","Set","Completed","1000040","B101Seat41","BJSHFG112"
|
||||
"Javier","Gabriella","Ramos","11/20/2014","Elgine","713-485-5600","US","Operations","Sr. Operation specialist","Kristopher Kapoor","11/23/2024","jgr","Set","Completed","1000041","B101Seat42","BJSHFG113"
|
||||
"George","James","Rana","11/20/2014","Elgine","713-485-5601","US","Research and Development","Product Engineering","Ryan Brown","11/23/2024","gjr","Set","Completed","1000042","B101Seat43","BJSHFG114"
|
||||
"Wayne","","Nara","11/20/2014","Elgine","713-485-5602","US","Research and Development","Data Scentist ","Ryan Brown","11/23/2024","wxn","Set","Completed","1000043","B101Seat44","BJSHFG115"
|
||||
"Brittney","Gregory","Cai","11/20/2014","Elgine","713-485-5603","US","Research and Development","Research Assistant ","Ryan Brown","11/23/2024","bgc","Set","Completed","1000044","B101Seat45","BJSHFG116"
|
||||
"Devin","","Hernandez","11/20/2014","Aurora","713-485-5575","US","Human Resources","HR Specialist ","Ryan Brown","11/23/2024","dxh1","Set","Completed","1000045","B101Seat46","BJSHFG117"
|
||||
"Jerry","Heidi","Shen","11/20/2014","Aurora","713-485-5576","US","Human Resources","HR Specialist ","Ryan Brown","11/23/2024","jhs","Set","Completed","1000046","B101Seat47","BJSHFG118"
|
||||
"Wayne","Kelvin","Chande","11/20/2014","Aurora","713-485-5577","US","Human Resources","HR Specialist ","Ryan Brown","11/23/2024","wkc","Set","Completed","1000047","B101Seat48","BJSHFG119"
|
||||
"Pamela","Kristen","Srini","10/30/2024","Aurora","713-485-5574","US","Humance Resources","HR Specialist ","Ryan Brown","11/9/2024","pks","Set","Completed","1000048","B101Seat49","BJSHFG120"
|
||||
"Cameron","Ashley","Rodriguez","10/30/2019","Aurora","713-485-5557","US","Accounting and Finance","Accountant","Edward Hernandez","11/16/2024","car","Set","Completed","1000049","B101Seat50","BJSHFG121"
|
||||
"Peter","Ronald","Nara","11/20/2014","Aurora","713-485-5558","US","Accounting and Finance","Accountant","Edward Hernandez","11/23/2024","prn","Set","Completed","1000050","B101Seat51","BJSHFG122"
|
||||
"Theodore","Jon","Diaz","11/20/2014","Aurora","713-485-5559","US","Accounting and Finance","Accountant","Edward Hernandez","11/23/2024","tjd","Set","Completed","1000051","B101Seat52","BJSHFG123"
|
||||
"Christine","Ruth","Nara","11/20/2014","Aurora","713-485-5560","US","Art and Design","Art and Design Manager","Ryan Brown","11/23/2024","crn","Set","Completed","1000052","B101Seat53","BJSHFG124"
|
||||
"Latoya","Jamie","Shen","11/20/2014","Aurora","713-485-5561","US","Art and Design","UX design","Christine Nara","11/23/2024","ljs","Set","Completed","1000053","B101Seat54","BJSHFG125"
|
||||
"Stephanie","Angela","Cox","11/20/2014","Aurora","713-485-5562","US","Art and Design","UX design","Christine Nara","11/23/2024","sac","Set","Completed","1000054","B101Seat55","BJSHFG126"
|
||||
"Joshua","Hunter","Lee","11/20/2014","Aurora","713-485-5563","US","Art and Design","Backend UI design","Christine Nara","11/23/2024","jhl","Set","Completed","1000055","B101Seat56","BJSHFG127"
|
||||
"Dalton","","Wood","11/20/2014","Aurora","713-485-5564","US","Art and Design","Animation design","Christine Nara","11/23/2024","dxw","Set","Completed","1000056","B101Seat57","BJSHFG128"
|
||||
"Clayton","Sarah","Shan","11/20/2014","Aurora","713-485-5565","US","Content and Review ","Content and Review Manager","Ryan Brown","11/23/2024","css","Set","Completed","1000057","B101Seat58","BJSHFG129"
|
||||
"Paige","Mason","Peterson","11/20/2014","Aurora","713-485-5566","US","Content and Review","Content creator","Clayton Shan","11/23/2024","pmp","Set","Completed","1000058","B101Seat59","BJSHFG130"
|
||||
"Dalton","Jeremiah","Hill","11/20/2014","Aurora","713-485-5567","US","Content and Review","Content creator","Clayton Shan","11/23/2024","djh","Set","Completed","1000059","B101Seat60","BJSHFG131"
|
||||
"Johnathan","","Srini","11/20/2014","Aurora","713-485-5568","US","Content and Review","Content creator","Clayton Shan","11/23/2024","jxs","Set","Completed","1000060","B101Seat61","BJSHFG132"
|
||||
"Beth","Willie","Ruiz","11/20/2014","Aurora","713-485-5569","US","Content and Review","Content creator","Clayton Shan","11/23/2024","bwr","Set","Completed","1000061","B101Seat62","BJSHFG133"
|
||||
"Rachel","Robert","Davis","11/20/2014","Aurora","713-485-5570","US","Content and Review","Content creator","Clayton Shan","11/23/2024","rrd","Set","Completed","1000062","B101Seat63","BJSHFG134"
|
||||
"Dustin","Rebecca","Nath","11/20/2014","Aurora","713-485-5571","US","Content and Review","Content creator","Clayton Shan","11/23/2024","drn","Set","Completed","1000063","B101Seat64","BJSHFG135"
|
||||
"Chloe","","Reed","11/20/2014","Aurora","713-485-5572","US","Content and Review","Content editor","Clayton Shan","11/23/2024","cxr","Set","Completed","1000064","B101Seat65","BJSHFG136"
|
||||
"Devin","","Hernandez","11/20/2014","Aurora","713-485-5575","US","Humance Resources","HR Specialist ","Ryan Brown","11/23/2024","dxh","Set","Completed","1000065","B101Seat66","BJSHFG137"
|
||||
"Jerry","Heidi","Shen","11/20/2014","Aurora","713-485-5576","US","Humance Resources","HR Specialist ","Ryan Brown","11/23/2024","jhs","Set","Completed","1000066","B101Seat67","BJSHFG138"
|
||||
"Wayne","Kelvin","Chande","11/20/2014","Aurora","713-485-5577","US","Humance Resources","HR Specialist ","Ryan Brown","11/23/2024","wkc","Set","Completed","1000067","B101Seat68","BJSHFG139"
|
||||
"Katelyn","Destiny","Adams","11/20/2014","Aurora","713-485-5578","US","Information Technology","Service Desk Manager","Ryan Brown","11/23/2024","kda","Set","Completed","1000068","B101Seat69","BJSHFG140"
|
||||
"Cassie","Jasmine","Kennedy","11/20/2014","Aurora","713-485-5579","US","Information Technology","Service Desk","Katelyn Adams","11/23/2024","cjk","Set","Completed","1000069","B101Seat70","BJSHFG141"
|
||||
"Kimberly","","Kelly","11/20/2014","Elgine","713-485-5580","US","Information Technology","Service Desk","Katelyn Adams","11/23/2024","kxk","Set","Completed","1000070","B101Seat71","BJSHFG142"
|
||||
"Madeline","Destiny","Phillips","11/20/2014","Aurora","713-485-5581","US","Marketing","Social Media Manager","Ryan Brown","11/23/2024","mdp","Set","Completed","1000071","B101Seat72","BJSHFG143"
|
||||
"Kristy","Victoria","Hernandez","11/20/2014","Aurora","713-485-5582","US","Marketing","Marketing Professional","Madeline Phillips","11/23/2024","kvh","Set","Completed","1000072","B101Seat73","BJSHFG144"
|
||||
"Ashley","Jennifer","Wood","11/20/2014","Aurora","713-485-5583","US","Marketing","Content Markerting Specialist","Madeline Phillips","11/23/2024","ajw","Set","Completed","1000073","B101Seat74","BJSHFG145"
|
||||
"Donald","Aaron","McDonald","11/20/2014","Aurora","713-485-5584","US","Marketing","Markerting Assistant ","Madeline Phillips","11/23/2024","dam","Set","Completed","1000074","B101Seat75","BJSHFG146"
|
||||
"Kristopher","","Kapoor","11/20/2014","Elgine","713-485-5586","US","Operations","Operation Manager","Ryan Brown","11/23/2024","kxk1","Set","Completed","1000075","B101Seat76","BJSHFG147"
|
||||
"Alex","Edgar","Allen","11/20/2014","Elgine","713-485-5587","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","aea","Set","Completed","1000076","B101Seat77","BJSHFG148"
|
||||
"Sara","Melanie","Young","11/20/2014","Elgine","713-485-5588","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","smy","Set","Completed","1000077","B101Seat78","BJSHFG149"
|
||||
"Brent","Eddie","Wang","11/20/2014","Elgine","713-485-5589","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","bew","Set","Completed","1000078","B101Seat79","BJSHFG150"
|
||||
"Karl","","Xie","11/20/2014","Elgine","713-485-5590","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","kxx","Set","Completed","1000079","B101Seat80","BJSHFG151"
|
||||
"Lee","Kaitlyn","Romero","11/20/2014","Elgine","713-485-5591","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","lkr","Set","Completed","1000080","B101Seat81","BJSHFG152"
|
||||
"Joseph","","Smith","11/20/2014","Elgine","713-485-5592","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","jxs1","Set","Completed","1000081","B101Seat82","BJSHFG153"
|
||||
"Luis","Holly","Hall","11/20/2014","Elgine","713-485-5593","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","lhh","Set","Completed","1000082","B101Seat83","BJSHFG154"
|
||||
"Colleen","Bradley","Lin","11/20/2014","Elgine","713-485-5594","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","cbl","Set","Completed","1000083","B101Seat84","BJSHFG155"
|
||||
"Darryl","","He","11/20/2014","Elgine","713-485-5595","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","dxh","Set","Completed","1000084","B101Seat85","BJSHFG156"
|
||||
"Alexis","Misty","Flores","11/20/2014","Elgine","713-485-5596","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","amf","Set","Completed","1000085","B101Seat86","BJSHFG157"
|
||||
"Renee","Autumn","Gill","11/20/2014","Elgine","713-485-5597","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","rag","Set","Completed","1000086","B101Seat87","BJSHFG158"
|
||||
"Bianca","","Hu","11/20/2014","Elgine","713-485-5598","US","Operations","Operation specialist","Kristopher Kapoor","11/23/2024","bxh","Set","Completed","1000087","B101Seat88","BJSHFG159"
|
||||
"Abigail","Jared","Peterson","11/20/2014","Elgine","713-485-5599","US","Operations","Sr. Operation specialist","Kristopher Kapoor","11/23/2024","ajp","Set","Completed","1000088","B101Seat89","BJSHFG160"
|
||||
"Javier","Gabriella","Ramos","11/20/2014","Elgine","713-485-5600","US","Operations","Sr. Operation specialist","Kristopher Kapoor","11/23/2024","jgr","Set","Completed","1000089","B101Seat90","BJSHFG161"
|
||||
"George","James","Rana","11/20/2014","Elgine","713-485-5601","US","Research and Development","Product Engineering","Ryan Brown","11/23/2024","gjr","Set","Completed","1000090","B101Seat91","BJSHFG162"
|
||||
"Wayne","","Nara","11/20/2014","Elgine","713-485-5602","US","Research and Development","Data Scentist ","Ryan Brown","11/23/2024","wxn","Set","Completed","1000091","B101Seat92","BJSHFG163"
|
||||
"Brittney","Gregory","Cai","11/20/2014","Elgine","713-485-5603","US","Research and Development","Research Assistant ","Ryan Brown","11/23/2024","bgc","Set","Completed","1000092","B101Seat93","BJSHFG164"
|
||||
"Devin","","Hernandez","11/20/2014","Aurora","713-485-5575","US","Human Resources","HR Specialist ","Ryan Brown","11/23/2024","dxh1","Set","Completed","1000093","B101Seat94","BJSHFG165"
|
||||
"Jerry","Heidi","Shen","11/20/2014","Aurora","713-485-5576","US","Human Resources","HR Specialist ","Ryan Brown","11/23/2024","jhs","Set","Completed","1000094","B101Seat95","BJSHFG166"
|
||||
"Wayne","Kelvin","Chande","11/20/2014","Aurora","713-485-5577","US","Human Resources","HR Specialist ","Ryan Brown","11/23/2024","wkc","Set","Completed","1000095","B101Seat96","BJSHFG167"
|
||||
"Kari","Justin","Hernandez","11/20/2014","Aurora","713-485-5585","US","Marketing","Product Marketing Assistant","Madeline Phillips","11/23/2024","kjh","Set","Completed","1000097","B101Seat98","BJSHFG169"
|
||||
"Angel","","Stewart","10/30/2019","Aurora","713-485-5565","US","Human Resources","Sr. HR Consultant","Ryan Brown","11/9/2024","axs","Set","Completed","1000096","B101Seat97","BJSHFG168"
|
||||
|
126
FinalUpdateUsers.ps1
Normal file
126
FinalUpdateUsers.ps1
Normal file
@ -0,0 +1,126 @@
|
||||
#Import logon scripts for all departments from the CSV file.
|
||||
$logonScripts = Import-Csv -Path "D:\Scripts\Data\LogonScript.csv"
|
||||
|
||||
#The OU from which we start searching for the users
|
||||
$baseOU = "OU=Users,OU=ITLifeSkills,DC=hq,DC=itlifeskills,DC=local"
|
||||
|
||||
#The date users get updated
|
||||
$updatedDate = (Get-Date).ToString("yyyy-MM-dd")
|
||||
|
||||
#Construct paths to CSV files
|
||||
$basePath = "D:\Departments\Human Resources\UserManagement\"
|
||||
$updateuserPath = $basePath + "UpdateUsers.csv"
|
||||
$currentuserPath = $basePath + "Completed\CurrentUsers.csv"
|
||||
|
||||
#$UpdateUsers is to store all users with updated information .
|
||||
$UpdatedUserPath = $basePath + "Completed\UpdatedUsers.csv"
|
||||
|
||||
#In ITLifeSkills, CurrentUsers.csv contains all current users in ITLifeSkills.
|
||||
#Therefore, updating users in AD will require us to update CurrentUsers.csv
|
||||
$CurrentUsers = Import-Csv -Path $currentuserPath
|
||||
|
||||
|
||||
function Update-Property( $propertyName, $currentValue, $newValue ){
|
||||
|
||||
#If the propertyName is Manager, then update its value from Name to Distinguished Name.
|
||||
#This allow us to compare with the Distinguished Name of the manager of the user stored in AD
|
||||
if($propertyName -eq "Manager"){
|
||||
$managerName = $newValue
|
||||
$newValue = (Get-ADUser -Filter 'Name -eq $managerName').DistinguishedName
|
||||
}
|
||||
|
||||
#Determine if the new value is not null and different from current value of the user stored in AD
|
||||
if(($newValue) -and ($newValue -ne $currentValue)){
|
||||
|
||||
#If Yes, add the property with the new value into the $userProperties hash table
|
||||
$userProperties.Add($propertyName, $newValue)
|
||||
|
||||
#Also, update the property of the current user in the CurrentUsers.csv with the new value
|
||||
if($propertyName -eq "Manager"){
|
||||
$currentUser.$propertyName = $managerName
|
||||
}
|
||||
else{
|
||||
$currentUser.$propertyName = $newValue
|
||||
}
|
||||
|
||||
#If the Department of the user is changed
|
||||
if($propertyName -eq "Department"){
|
||||
#Get the LogOnScript for the NEW department to update to the user
|
||||
$script = ($logonScripts | where {$_.Department -eq $newValue}).LogonScript
|
||||
#Add the ScriptPath property with the $script variable to the $userProperties hash table
|
||||
$userProperties.Add("ScriptPath",$script)
|
||||
|
||||
#Find the Distinguished name of the NEW department OU
|
||||
$OU = (Get-ADOrganizationalUnit -SearchBase $baseOU -Filter 'Name -eq $newValue').DistinguishedName
|
||||
|
||||
#Move the user to the new department OU
|
||||
Move-ADObject -Identity $updateUser.DistinguishedName -TargetPath $OU
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#Check to see if the UpdateUsers.csv file has been uploaded to the right location
|
||||
$updatefile = Test-Path $updateuserPath
|
||||
|
||||
if($updatefile){
|
||||
|
||||
#Import users who are requested to update their information
|
||||
#from UpdateUsers.csv file.
|
||||
$users = Import-Csv -Path $updateuserPath
|
||||
|
||||
#Read each user that is to be updated from the UpdateUsers.csv file.
|
||||
foreach($user in $users){
|
||||
|
||||
#Get the SamAccountName of the first user and store it in the $samAccount variable.
|
||||
$samAccount = $user.SamAccountName
|
||||
|
||||
#Construct the hash table of $userproperties initially including only SamAccountName
|
||||
$userProperties = @{
|
||||
Identity = $samAccount
|
||||
|
||||
}
|
||||
|
||||
#Read the user with same $samAccount from the CurrentUsers.csv to be updated with the new properties
|
||||
$currentUser = $CurrentUsers | where {$_.SamAccountName -eq $samAccount}
|
||||
|
||||
#Read the user with same $samAccount from Active Directory to determine which properties to be updated
|
||||
$updateUser = Get-ADUser -Identity $samAccount -Properties *
|
||||
|
||||
#For the current user read from the UpdateUsers.csv file, get only the Name and Value properties
|
||||
#filter to only the properties that are not Empty and not equal to the “MiddleName”.
|
||||
$updateProperties = $user.PSObject.Properties | Select Name, Value |
|
||||
where {($_.value -ne "")-and ($_.Name -ne "MiddleName")}
|
||||
|
||||
#Loop through each property of the current user read from UpdateUsers.csv
|
||||
foreach($property in $updateProperties){
|
||||
#Build up the property Name and its Value
|
||||
$propertyName = $property.Name
|
||||
$propertyValue = $property.Value
|
||||
|
||||
#Get the current value of the property with the same
|
||||
#Name from the user stored in Active Directory
|
||||
$currentValue = $updateUser.$propertyName
|
||||
|
||||
#Update the property using the Update-Property custom function
|
||||
Update-Property $propertyName $currentValue $propertyValue
|
||||
}
|
||||
|
||||
#After the foreach loop completed,
|
||||
#we will have the @userProperties hash table with the properties being updated
|
||||
Set-ADUser @userProperties
|
||||
#Add the updated date to each update user
|
||||
$user | Add-Member -MemberType NoteProperty -Name "UpdatedOn" -Value $updatedDate
|
||||
|
||||
}
|
||||
#Append all the users in the UpdateUsers.csv file
|
||||
#along with the updated date to the UpdatedUsers.csv file
|
||||
$users | Export-Csv -Path $UpdatedUserPath -NoTypeInformation -Append
|
||||
Remove-Item -Path $updateuserPath
|
||||
|
||||
#At this point the $CurrentUsers contains all users with updated information
|
||||
$CurrentUsers | Export-Csv -Path $currentuserPath -NoTypeInformation
|
||||
}
|
||||
|
||||
|
||||
|
||||
50
NewUsers.csv
Normal file
50
NewUsers.csv
Normal file
@ -0,0 +1,50 @@
|
||||
FirstName,MiddleName,LastName,Description,Office,PhoneNumber,Country,Department,JobTitle,Manager
|
||||
Edward,Garrett,Hernandez,10/30/2019,Aurora,713-485-5555,US,Accounting and Finance,Sr. Accountant Manager,Ryan Brown
|
||||
Angel,,Stewart,10/30/2019,Aurora,713-485-5556,US,Accounting and Finance,Finance Analyst,Edward Hernandez
|
||||
Cameron,Ashley,Rodriguez,10/30/2019,Aurora,713-485-5557,US,Accounting and Finance,Accountant,Edward Hernandez
|
||||
Peter,Ronald,Nara,10/30/2019,Aurora,713-485-5558,US,Accounting and Finance,Accountant,Edward Hernandez
|
||||
Theodore,Jon,Diaz,10/30/2019,Aurora,713-485-5559,US,Accounting and Finance,Accountant,Edward Hernandez
|
||||
Christine,Ruth,Nara,10/30/2019,Aurora,713-485-5560,US,Art and Design,Art and Design Manager,Ryan Brown
|
||||
Latoya,Jamie,Shen,10/30/2019,Aurora,713-485-5561,US,Art and Design,UX design,Christine Nara
|
||||
Stephanie,Angela,Cox,10/30/2019,Aurora,713-485-5562,US,Art and Design,UX design,Christine Nara
|
||||
Joshua,Hunter,Lee,10/30/2019,Aurora,713-485-5563,US,Art and Design,Backend UI design,Christine Nara
|
||||
Dalton,,Wood,10/30/2019,Aurora,713-485-5564,US,Art and Design,Animation design,Christine Nara
|
||||
Clayton,Sarah,Shan,10/30/2019,Aurora,713-485-5565,US,Content and Review ,Content and Review Manager,Ryan Brown
|
||||
Paige,Mason,Peterson,10/30/2019,Aurora,713-485-5566,US,Content and Review,Content creator,Clayton Shan
|
||||
Dalton,Jeremiah,Hill,10/30/2019,Aurora,713-485-5567,US,Content and Review,Content creator,Clayton Shan
|
||||
Johnathan,,Srini,10/30/2019,Aurora,713-485-5568,US,Content and Review,Content creator,Clayton Shan
|
||||
Beth,Willie,Ruiz,10/30/2019,Aurora,713-485-5569,US,Content and Review,Content creator,Clayton Shan
|
||||
Rachel,Robert,Davis,10/30/2019,Aurora,713-485-5570,US,Content and Review,Content creator,Clayton Shan
|
||||
Dustin,Rebecca,Nath,10/30/2019,Aurora,713-485-5571,US,Content and Review,Content creator,Clayton Shan
|
||||
Chloe,,Reed,10/30/2019,Aurora,713-485-5572,US,Content and Review,Content editor,Clayton Shan
|
||||
Ryant,,Brown,10/30/2019,Aurora,713-485-5573,US,Humance Resources,CEO ,N/A
|
||||
Pamela,Kristen,Srini,10/30/2019,Aurora,713-485-5574,US,Humance Resources,HR Specialist ,Ryan Brown
|
||||
Devin,,Hernandez,10/30/2019,Aurora,713-485-5575,US,Humance Resources,HR Specialist ,Ryan Brown
|
||||
Jerry,Heidi,Shen,10/30/2019,Aurora,713-485-5576,US,Humance Resources,HR Specialist ,Ryan Brown
|
||||
Wayne,Kelvin,Chande,10/30/2019,Aurora,713-485-5577,US,Humance Resources,HR Specialist ,Ryan Brown
|
||||
Katelyn,Destiny,Adams,10/30/2019,Aurora,713-485-5578,US,Information Technology,Service Desk Manager,Ryan Brown
|
||||
Cassie,Jasmine,Kennedy,10/30/2019,Aurora,713-485-5579,US,Information Technology,Service Desk,Katelyn Adams
|
||||
Kimberly,Alfredo,Kelly,10/30/2019,Elgine,713-485-5580,US,Information Technology,Service Desk,Katelyn Adams
|
||||
Madeline,Destiny,Phillips,10/30/2019,Aurora,713-485-5581,US,Marketing,Social Media Manager,Ryan Brown
|
||||
Kristy,Victoria,Hernandez,10/30/2019,Aurora,713-485-5582,US,Marketing,Marketing Professional,Madeline Phillips
|
||||
Ashley,Jennifer,Wood,10/30/2019,Aurora,713-485-5583,US,Marketing,Content Markerting Specialist,Madeline Phillips
|
||||
Donald,Aaron,McDonald,10/30/2019,Aurora,713-485-5584,US,Marketing,Markerting Assistant ,Madeline Phillips
|
||||
Kari,Justin,Hernandez,10/30/2019,Aurora,713-485-5585,US,Marketing,Product Marketing Assistant,Madeline Phillips
|
||||
Kristopher,,Kapoor,10/30/2019,Elgine,713-485-5586,US,Operations,Operation Manager,Ryan Brown
|
||||
Alex,Edgar,Allen,10/30/2019,Elgine,713-485-5587,US,Operations,Operation specialist,Kristopher Kapoor
|
||||
Sara,Melanie,Young,10/30/2019,Elgine,713-485-5588,US,Operations,Operation specialist,Kristopher Kapoor
|
||||
Brent,Eddie,Wang,10/30/2019,Elgine,713-485-5589,US,Operations,Operation specialist,Kristopher Kapoor
|
||||
Karl,,Xie,10/30/2019,Elgine,713-485-5590,US,Operations,Operation specialist,Kristopher Kapoor
|
||||
Lee,Kaitlyn,Romero,10/30/2019,Elgine,713-485-5591,US,Operations,Operation specialist,Kristopher Kapoor
|
||||
Joseph,,Smith,10/30/2019,Elgine,713-485-5592,US,Operations,Operation specialist,Kristopher Kapoor
|
||||
Luis,Holly,Hall,10/30/2019,Elgine,713-485-5593,US,Operations,Operation specialist,Kristopher Kapoor
|
||||
Colleen,Bradley,Lin,10/30/2019,Elgine,713-485-5594,US,Operations,Operation specialist,Kristopher Kapoor
|
||||
Darryl,,He,10/30/2019,Elgine,713-485-5595,US,Operations,Operation specialist,Kristopher Kapoor
|
||||
Alexis,Misty,Flores,10/30/2019,Elgine,713-485-5596,US,Operations,Operation specialist,Kristopher Kapoor
|
||||
Renee,Autumn,Gill,10/30/2019,Elgine,713-485-5597,US,Operations,Operation specialist,Kristopher Kapoor
|
||||
Bianca,,Hu,10/30/2019,Elgine,713-485-5598,US,Operations,Operation specialist,Kristopher Kapoor
|
||||
Abigail,Jared,Peterson,10/30/2019,Elgine,713-485-5599,US,Operations,Sr. Operation specialist,Kristopher Kapoor
|
||||
Javier,Gabriella,Ramos,10/30/2019,Elgine,713-485-5600,US,Operations,Sr. Operation specialist,Kristopher Kapoor
|
||||
George,James,Rana,10/30/2019,Elgine,713-485-5601,US,Research and Development,Product Engineering,Ryan Brown
|
||||
Wayne,,Nara,10/30/2019,Elgine,713-485-5602,US,Research and Development,Data Scentist ,Ryan Brown
|
||||
Brittney,Gregory,Cai,10/30/2019,Elgine,713-485-5603,US,Research and Development,Research Assistant ,Ryan Brown
|
||||
|
21
SetHomeDirectory.ps1
Normal file
21
SetHomeDirectory.ps1
Normal file
@ -0,0 +1,21 @@
|
||||
#path to the Users shared folder
|
||||
$homepath = "\\hq\CorporateData\Users\"
|
||||
|
||||
#initial OU where the script starts searching for the users
|
||||
$basepath = "OU=Users,OU=ITLifeSkills,DC=hq,DC=itlifeskills,DC=local"
|
||||
$users = Get-ADUser -SearchBase $basepath -Filter *
|
||||
|
||||
|
||||
foreach($user in $users){
|
||||
#Get the current user identity
|
||||
$identity = $user.SamAccountName
|
||||
#Get the current user name
|
||||
$name = $user.Name
|
||||
|
||||
#construct the homedirectory path
|
||||
$homedirectory = $homepath + $name
|
||||
|
||||
#Update the current user with the new path to the Home directory.
|
||||
Set-ADUser -Identity $identity -HomeDirectory $homedirectory
|
||||
}
|
||||
|
||||
58
Setfolderpermissions.ps1
Normal file
58
Setfolderpermissions.ps1
Normal file
@ -0,0 +1,58 @@
|
||||
|
||||
# Get a list of folder folders
|
||||
$domainUsers = "HQ\Domain Users"
|
||||
$folderPath = "D:\Projects\"
|
||||
$folders = (Get-ChildItem -Path $folderPath).Name
|
||||
|
||||
|
||||
#Loop throug each folder in all the folders found in the D:\Departments folder
|
||||
foreach ($folder in $folders){
|
||||
|
||||
|
||||
if($folder -ne "Accounting and Finance"){ #Only run the script to apply the permission on the Accounting and Finance folder
|
||||
|
||||
|
||||
$path = $folderPath + $folder #Set path for the current folder
|
||||
$name = $folder.Split(" ") #Split the folder name by the space to construct the group name
|
||||
$groupName= "HQ\grp" # Set the intial group name
|
||||
foreach($word in $name){ #Loop through each word in the folder name
|
||||
if($word -ne "and"){ #If the word is not "and"
|
||||
#Add the initial group name with a "-" and the current word in the folder name and convert it to lower case
|
||||
$groupName = $groupName + "-" + ($word).ToLower()
|
||||
|
||||
}
|
||||
} #After the for loop we will have the group name. For example, HQ\grp-accounting-finance
|
||||
|
||||
|
||||
###Disable inheritance and preserve inherited access rules
|
||||
$aclList = Get-Acl -Path $path
|
||||
$isProtected = $true #Protect the item from being inherited
|
||||
$preserveInheritance = $true #Keep all the entries in the current ACL
|
||||
$aclList.SetAccessRuleProtection($isProtected, $preserveInheritance)
|
||||
Set-Acl -Path $path -AclObject $aclList
|
||||
|
||||
## Remove Domain Users
|
||||
$aclList = Get-ACL -Path $path
|
||||
|
||||
$aclList.Access | Where-Object { $_.IdentityReference.Value -eq $domainUsers } |
|
||||
ForEach-Object {$aclList.RemoveAccessRule($_)} | Out-Null
|
||||
Set-Acl -Path $path -AclObject $aclList
|
||||
|
||||
# Prepare the list of the permission properties to assign to the folder
|
||||
$aclList = Get-ACL -Path $path
|
||||
$identity = $groupName
|
||||
$fileSystemRights = "Modify"
|
||||
$InheritanceFlags = "ContainerInherit, ObjectInherit" #Apply to this folder, subfolders and files
|
||||
$type = "Allow"
|
||||
|
||||
# Create a new access rule containing the permission properties to assign to the folder
|
||||
$fileSystemAccessRuleArgumentList = $identity, $fileSystemRights, $InheritanceFlags, "None", $type
|
||||
$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList
|
||||
|
||||
# Apply the new rule to the folder
|
||||
$aclList.AddAccessRule($fileSystemAccessRule)
|
||||
Set-Acl -Path $path -AclObject $aclList
|
||||
|
||||
##$aclList | Select *
|
||||
}
|
||||
}
|
||||
3
UpdateUsers.csv
Normal file
3
UpdateUsers.csv
Normal file
@ -0,0 +1,3 @@
|
||||
SamAccountName,GivenName,MiddleName,Surname,Description,Office,OfficePhone,Country,Department,Title,Manager
|
||||
axs,Angel,,Stewart,10/30/2019,Aurora,713-485-5565,US,Human Resources,Sr. HR Consultant,Ryan Brown
|
||||
kjh,Kari,Justin,Hernandez,11/20/2014,Aurora,713-485-5595,US,Accounting and Finance,Accountant,Edward Hernandez
|
||||
|
125
UpdateUsers.ps1
Normal file
125
UpdateUsers.ps1
Normal file
@ -0,0 +1,125 @@
|
||||
#In ITLifeSkills, CurrentUsers.csv contains all current users in ITLifeSkills.
|
||||
#Therefore, updating users in AD will require us to update their information in CurrentUsers.csv file
|
||||
$CurrentUsersFile = "C:\Scripts\Data\CurrentUsers.csv"
|
||||
$CurrentUsers = Import-Csv -Path $CurrentUsersFile
|
||||
|
||||
#Import logon scripts for all departments from the CSV file.
|
||||
$logonScripts = Import-Csv -Path "C:\Scripts\Data\LogonScript.csv"
|
||||
|
||||
#Import users who are requested to update their information from UpdateUsers.csv file.
|
||||
$users = Import-Csv -Path "C:\Scripts\Data\UpdateUsers.csv" | where {$_.SamAccountName -eq "axs"}
|
||||
|
||||
|
||||
#$UpdateUsers is to store all users with updated information which allow to filter and to export CurrentUsers.csv file.
|
||||
$UpdateUsers = @()
|
||||
|
||||
#The OU from which we start searching for the users
|
||||
$baseOU = "OU=Users,OU=ITLifeSkills,DC=hq,DC=itlifeskills,DC=local"
|
||||
|
||||
function Update-Property( $propertyName, $currentValue, $newValue ){
|
||||
|
||||
#If the propertyName is Manager, then update its value from Name to Distinguished Name.
|
||||
#This allow us to compare with the Distinguished Name of the manager of the user stored in AD
|
||||
if($propertyName -eq "Manager"){
|
||||
$managerName = $newValue
|
||||
$newValue = (Get-ADUser -Filter 'Name -eq $managerName').DistinguishedName
|
||||
}
|
||||
|
||||
#Determine if the new value is not null and different from current value of the user stored in AD
|
||||
if(($newValue) -and ($newValue -ne $currentValue)){
|
||||
|
||||
#If Yes, add the property with the new value into the $userProperties hash table
|
||||
$userProperties.Add($propertyName, $newValue)
|
||||
|
||||
#Also, update the property of the current user in the CurrentUsers.csv with the new value
|
||||
if($propertyName -eq "Manager"){
|
||||
$currentUser.$propertyName = $managerName
|
||||
}
|
||||
else{
|
||||
$currentUser.$propertyName = $newValue
|
||||
}
|
||||
|
||||
#If the Department of the user is changed
|
||||
if($propertyName -eq "Department"){
|
||||
#Get the LogOnScript for the NEW department to update to the user
|
||||
$script = ($logonScripts | where {$_.Department -eq $newValue}).LogonScript
|
||||
#Add the ScriptPath property with the $script variable to the $userProperties hash table
|
||||
$userProperties.Add("ScriptPath",$script)
|
||||
|
||||
#Find the Distinguished name of the NEW department OU
|
||||
$OU = (Get-ADOrganizationalUnit -SearchBase $baseOU -Filter 'Name -eq $newValue').DistinguishedName
|
||||
|
||||
#Move the user to the new department OU
|
||||
Move-ADObject -Identity $updateUser.DistinguishedName -TargetPath $OU
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Read each user that is to be updated from the UpdateUsers.csv file.
|
||||
|
||||
foreach($user in $users){
|
||||
|
||||
#Get the SamAccountName of the first user and store it in the $samAccount variable.
|
||||
$samAccount = $user.SamAccountName
|
||||
|
||||
#Construct the hash table of $userproperties initially including only SamAccountName
|
||||
$userProperties = @{
|
||||
Identity = $samAccount
|
||||
|
||||
}
|
||||
|
||||
#Read the user with same $samAccount from the CurrentUsers.csv to be updated with the new properties
|
||||
$currentUser = $CurrentUsers | where {$_.SamAccountName -eq $samAccount}
|
||||
|
||||
#Read the user with same $samAccount from Active Directory to determine which properties to be updated
|
||||
$updateUser = Get-ADUser -Identity $samAccount -Properties *
|
||||
|
||||
#For the current user read from the UpdateUsers.csv file, get only the Name and Value properties
|
||||
#filter to only the properties that are not Empty and not equal to the “MiddleName”.
|
||||
$updateProperties = $user.PSObject.Properties | Select Name, Value | where {($_.value -ne "")-and ($_.Name -ne "MiddleName")}
|
||||
|
||||
#Loop through each property of the current user read from UpdateUsers.csv
|
||||
foreach($property in $updateProperties){
|
||||
#Build up the property Name and its Value
|
||||
$propertyName = $property.Name
|
||||
$propertyValue = $property.Value
|
||||
|
||||
#Get the current value of the property with the same Name from the user stored in Active Directory
|
||||
$currentValue = $updateUser.$propertyName
|
||||
|
||||
#Update the property using the Update-Property custom function
|
||||
Update-Property $propertyName $currentValue $propertyValue
|
||||
}
|
||||
|
||||
#After the foreach loop completed, we will have the @userProperties hash table with the properties being updated
|
||||
Set-ADUser @userProperties
|
||||
|
||||
#The properties of the $currentUser includes with updated information
|
||||
#We store $currentUser into the $UpdateUsers
|
||||
$UpdateUsers += $currentUser
|
||||
|
||||
|
||||
}
|
||||
|
||||
#At this point the $UpdateUsers contains all users with updated information
|
||||
|
||||
#First we remove the CurrentUsers.csv which contain all current users.
|
||||
Remove-Item -Path $CurrentUsersFile
|
||||
|
||||
#Then build a list of samAccountNames of all users that got updated
|
||||
$updatedSamAccount = $UpdateUsers.SamAccountName
|
||||
|
||||
#Exclude users that got updated from the $CurrentUsers
|
||||
$CurrentUsers | where {$_.SamAccountName -notin $updatedSamAccount} |
|
||||
|
||||
#Export them to CurrentUsers.csv file
|
||||
#The CurrentUsers.csv now only contains users that are not updated
|
||||
Export-Csv -Path $CurrentUsersFile -NoTypeInformation
|
||||
|
||||
#Finally, append the users that got updated to the CurrentUsers.csv
|
||||
$UpdateUsers | Export-Csv $CurrentUsersFile -Append
|
||||
|
||||
|
||||
#>
|
||||
Loading…
Reference in New Issue
Block a user