getting a “Cannot bind argument to parameter ‘Identity’ because it is null” in this script :
# Import Exchange Online PowerShell Module
Import-Module ExchangeOnlineManagement
# Connect to Exchange Online
Connect-ExchangeOnline
# Path to the CSV file
$csvFilePath = "mypathblabla"
# Import the CSV file
$userList = Import-Csv -Path $csvFilePath
# Loop through each user in the CSV file and update the City and Country attributes
foreach ($user in $userList) {
$email = $user.Email
$city = $user.City
$country = $user.Country
# Update the user attributes
try {
Set-Mailbox -Identity $email -City $city -CountryOrRegion $country
Write-Host "Successfully updated $email with City: $city and Country: $country"
} catch {
Write-Host "Failed to update $email. Error: $_"
}
}
I gathered it to basically put 2 different attributes in the fields “city” and “country” on a loooong list of users 365 mails contained in a csv file.
Could someone explain to me what I am missing here ? (CSV is in the good format : Email,City,Country).
Thank you very much in advance
- Correct CSV
- Search the error
- Thought i should learn powershell extensively for this extensive type of uses ?