PowerShell doesn’t have built-in support for reading Excel files, but we can use the ImportExcel module. You can install it using Install-Module -Name ImportExcel -Scope CurrentUser. 



Please replace "path_to_your_file.xlsx" with the actual path to your Excel file. This script needs to be run with an account that has the necessary permissions to modify user properties in Active Directory. 



------------------------------------Start Code---------------------------------------------


# Import the Active Directory and ImportExcel modules

Import-Module ActiveDirectory

Import-Module ImportExcel


# Specify the path to your Excel file

$excelFilePath = "path_to_your_file.xlsx"


# Import the Excel file

$users = Import-Excel -Path $excelFilePath


# Loop through each user in the Excel file

foreach ($user in $users) {

    # Get the UPN from the Excel file

    $upn = $user.UPN


    # Get the AD user with the matching UPN

    $adUser = Get-ADUser -Filter {UserPrincipalName -eq $upn}


    # If the user was found, disable "Password never expires"

    if ($adUser) {

        Set-ADUser -Identity $adUser -PasswordNeverExpires $false

    }

}




--------------------------------------End Code-------------------------------------------------