foreach ($AD_User in $ad) {
if ($file[0].sn -eq $AD_User.sn)
{
#Write-Host "BINGO FOUND IT"
#Ask Questions
$RightWrong = Read-Host 'NOTE: Is this the right Employee, You are working on? (Y/N)'
}
if ($RightWrong -eq "N") {[void]$foreach.moveNext()}
}
Clear-Host
$file = Import-Csv "c:\scripts\ad\temp\file.csv" -header sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber
$ad = Get-ADUser -filter * -Properties sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber -SearchBase "OU=OU,DC=colo,DC=pvt" | Select-Object sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber
Write-Host "Querying Employee from file against Active Directory"
Write-Host ""
Write-Host "++ FOUND THE FOLLOWING EMPLOYEE IN FILE +++++"
#Write-Host ""
Write-Host "LASTNAME: $($ [0].sn)"
Write-Host "FIRST NAME: $($ [0].givenName)"
Write-Host "DEPARTMENT: $($ [0].department)"
Write-Host "TITLE: $($ [0].title)"
Write-Host "TELEPHONE NUMBER: $($ [0].telephoneNumber)"
Write-Host "FLEX ID: $($ [0].employeeID)"
Write-Host "CLOCK NUMBER: $($ [0].employeeNumber)"
#Write-Host ""
Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
#Write-Host "Waiting for 5 seconds"
Start-Sleep -Seconds 5
foreach ($AD_User in $ad) {
if ($file[0].sn -eq $AD_User.sn)
{
#Write-Host "BINGO FOUND IT"
$FlagLastName = 1
Write-Host ""
Write-Host "==== FOUND THE FOLLOWING EMPLOYEE IN ACTIVE DIRECTORY =="
Write-Host "LASTNAME: $($AD_USER.sn)"
Write-Host "FIRST NAME: $($AD_USER.givenName)"
Write-Host "DEPARTMENT: $($AD_USER.department)"
Write-Host "TITLE: $($AD_USER.title)"
Write-Host "TELEPHONE NUMBER: $($AD_USER.telephoneNumber)"
Write-Host "EMPLOYEE ID: $($AD_USER.employeeID)"
Write-Host "EMPLOYEE NUMBER: $($AD_USER.employeeNumber)"
Write-Host "================================================================"
Write-Host ""
$RightWrong = Read-Host 'NOTE: Is this the right Employee, You are working on? (Y/N)'
Write-Host ""
}
If ($RightWrong -eq "N") {
[void]$foreach.moveNext()
}
If ($RightWrong -eq "Y"){
$YesNo = Read-Host 'NOTE: Is the EMPLOYEE Information FOUND In ACTIVE DIRECTORY CORRECT AGAINST The EMPLOYEE Information FOUND In the File? (Y/N)'
Write-Host ""
#Write-Host "YesNo Value: $($YesNo)"
If ($YesNo -eq "N")
{
Write-Host "Which of the following Employee information would you like to change in Active Directory ?"
Write-Host ""
$AD_User_Change = Read-Host '1 = LASTNAME. 2 = FIRST NAME. 3 = DEPARTMENT. 4 = TITLE. 5 = TELEPHONE NUMBER. 6 = EMPLOYEE ID. 7 = EMPLOYEE NUMBER'
}
switch ($AD_User_Change) {
1 {
Write-Host "1"
$InputLastName = Read-Host 'Type the new Last Name:'
Write-Host ""
$NewLastName = Read-Host "Are you sure, you want to replace the following lastname ""$($AD_User.sn)"" by ""$InputLastName"" (Y/N)"
if (($NewLastName -eq "y"))
{
Get-ADUser $AD_User.sAMAccountName | Set-ADUser -surname $InputLastName -DisplayName $($InputLastName+", "+$AD_USER.givenName) -ErrorAction SilentlyContinue -ErrorVariable Err1
Start-Sleep -Seconds 5
$NewName = $InputLastName+", "+$AD_USER.givenName
Get-ADUser $AD_User.sAMAccountName | Rename-ADObject -newname $NewName
Start-Sleep -Seconds 5
Write-Host "New LastName SET"
Start-Sleep -Seconds 30
}
}
2 {Write-Host "2"}
3 {Write-Host "3"}
4 {Write-Host "4"}
5 {Write-Host "5"}
6 {Write-Host "6"}
7 {Write-Host "7"}
}
Start-Sleep -Seconds 30
}
}
$adsearch = $ad | Where {$file[0].sn -eq $_.sn}
If ($adsearch -eq $null)
{Write-Host "USER DOES NOT EXIST"}
Else{"Start your script"}
Open in new window