add collumns to compare in v lookup excel

Hi Guys,
I am trying to import this excel from HR . Than i want to import the upn from excel and compare this to AD and add AD title and department collumns next to the original excel to check this in v-lookup.
This is the excel file: Excelfile
Now this is what i have got so far.

$Results = @()
$users = Import-Excel -Path "C:\Scripts\hcm\blabla\hcmusers.xlsx"

ForEach ($user in $users)
{
    $ADUser = Get-ADUser -Filter "UserPrincipalName -eq '$user.HCMEmail'"  | Select-Object Name,UserPrincipalName,Title,department
    $Results += New-Object PsObject -Property @{
        ADTitle = $ADUser.title
        ADdepartment = $ADUser.department
    }
}
$Results | Export-excel -Path "C:\Scripts\hcm\blabla\ADusers.xlsx" 

Now it seems that it doesnt iterate through all users. Can someone point me in the right direction?</p>
Many thanks!!!
edit: i have installed the importexcel module

Base variables will be expanded inside of double quotes, but properties of the variable require you enclose it in a subexpression.

$ADUser = Get-ADUser -Filter "UserPrincipalName -eq '$($user.HCMEmail)'" 

You also need to specify the additional AD properties on the Get-ADUser command.

$ADUser = Get-ADUser -Filter "UserPrincipalName -eq '$($user.HCMEmail)'" -Properties Title,Department 

Few other improvements could be made.

$users = Import-Excel -Path "C:\Scripts\hcm\blabla\hcmusers.xlsx"
 
$Results = ForEach ($user in $users)
{
    Get-ADUser -Filter "UserPrincipalName -eq '$($user.HCMEmail)'" -Properties Title,Department | ForEach-Object {
        [PSCustomObject]@{
            Name              = $_.name
            UserPrincipalName = $_.userprincipalname
            ADTitle           = $_.title
            ADdepartment      = $_.department
        }
    }
}

$Results | Export-excel -Path "C:\Scripts\hcm\blabla\ADusers.xlsx" 

Can also be rewritten like this

Import-Excel -Path "C:\Scripts\hcm\blabla\hcmusers.xlsx" | ForEach-Object {
    
    foreach($user in Get-ADUser -Filter "UserPrincipalName -eq '$($_.HCMEmail)'" -Properties Title,Department)
    {
        [PSCustomObject]@{
            Name              = $user.name
            UserPrincipalName = $user.userprincipalname
            ADTitle           = $user.title
            ADdepartment      = $user.department
        }
    }
} | Export-excel -Path "C:\Scripts\hcm\blabla\ADusers.xlsx" 

I’m not sure what module Import-Excel is coming from or how it works, but typically it’s recommended to use a CSV as it can be directly imported to a PSObject. Excel uses an old COM object and it’s quite a bit of extra work to code for rather than just using a csv. Here is an example with calculated expressions to rename columns and also add the columns from the csv so that you can do direct

$users = Import-Csv -Path "C:\Scripts\hcm\blabla\hcmusers.csv"
 
$results = ForEach ($user in $users) {
    Get-ADUser -Filter "UserPrincipalName -eq '$user.HCMEmail'"  | 
    Select-Object Name,
                UserPrincipalName,
                @{Name='ADTitle';Expression={$_.Title}},
                @{Name='ADDepartment';Expression={$_.department}},
                @{Name='JobTitle';Expression={$user.JobTitle}},
                @{Name='ADDepartment';Expression={$user.DepartmentName}}
}

$results | Where{$_.ADTitle -ne $_.JobTitle}