Hi,
Please see script below
Import-Module Adaxes
Import-Module ActiveDirectory
$databaseHost = "SQL.domain.net"
$databaseName = "Database"
$databaseUsername = "domain\Svc_Adaxes"
$databasePassword = ""
$employeeID = $Context.TargetObject.Get("EmployeeID")
$SqlQuery = "SELECT TimGEEmployeeDetails.EmployeeNumber , convert(varchar(10), TimGEEmployeeDetails.JoiningDate, 103) , convert(varchar(10), TimGEEmployeeDetails.LeavingDate, 103), " +,
"TimGEEmployeeDetails.Title , TimGEEmployeeDetails.Forename , TimGEEmployeeDetails.KnownAs , TimGEEmployeeDetails.Initials, " +,
"TimGEEmployeeDetails.Surname , TimGEEmployeeDetails.Reference, vw_domain_Departments.Description , Department, " +,
"vw_domain_JobDesc.Description , JobTitle , TcfGEEmployeeDetails.LMSJobFamily, PrsInductionSchedule.LineManager, " +,
"TimGEEmployeeDetails_1.FullName , TimBEEmployeeDetails.PrimaryLocation , StdBFCodeDescriptions.Description " +,
"FROM TimGEEmployeeDetails " +,
"LEFT JOIN TimBEEmployeeDetails ON TimGEEmployeeDetails.EmployeeNumber = TimBEEmployeeDetails.EmployeeNumber " +,
"LEFT JOIN vw_domain_JobDesc ON TimBEEmployeeDetails.JobTitle = vw_domain_JobDesc.DetailCode " +,
"LEFT JOIN vw_domain_Departments ON TimBEEmployeeDetails.Department = vw_domain_Departments.DetailCode " +,
"LEFT JOIN PrsInductionSchedule ON TimGEEmployeeDetails.EmployeeNumber = PrsInductionSchedule.EmployeeNumber " +,
"LEFT JOIN TcfGEEmployeeDetails ON TimGEEmployeeDetails.EmployeeNumber = TcfGEEmployeeDetails.EmployeeNumber " +,
"LEFT JOIN StdBFCodeDescriptions ON StdBFCodeDescriptions.TableCode = 'LOCD' " +,
"AND TimBEEmployeeDetails.PrimaryLocation = StdBFCodeDescriptions.DetailCode " +,
"LEFT JOIN TimGEEmployeeDetails AS TimGEEmployeeDetails_1 ON PrsInductionSchedule.LineManager = TimGEEmployeeDetails_1.EmployeeNumber "
$connectionString = "Data Source=$databaseHost; Database=$databaseName;"
if ($databaseUsername -eq $NULL)
{
$connectionString = $connectionString +
"Integrated Security=true;"
}
else
{
$connectionString = $connectionString +
"User ID=$databaseUsername;Password=$databasePassword;Integrated Security=true"
}
$Sqlconnection = New-Object System.Data.SqlClient.SqlConnection($connectionString)
$Sqlconnection.open()
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet) | Out-Null
#$SqlCmd.Dispose()
$SqlConnection.Close()
$Array = ForEach($Row in $Dataset.Tables[0].Rows){
$Record = New-Object PSCustomObject
ForEach($Col in $Dataset.Tables[0].Columns.ColumnName){
Add-Member -InputObject $Record -NotePropertyName $Col -NotePropertyValue $Row.$Col
}
$Record
#pause
if ($Record.EmployeeNumber.Contains($employeeID)){
break
}
}
$GetADUser = get-aduser -filter {EmployeeID -like $employeeID}
$UserSAM = $GetADUser.SamAccountName
$TrimJob = $Record.Description1.Replace(' ','')
$Jobtitle = $Trimjob+$Record.Department
Set-ADuser -Identity $UserSAM -Replace @{BusinessCategory=$Record.LMSJobFamily; extensionAttribute1=$Jobtitle}