在 Microsoft 365 中用於設定 Office 應用程式、兌換產品金鑰和啟動授權的流程。
Dear Mr Lo Yun Lung
Thank you for the response. I appreciate you sharing the screenshots.
With reference to the screenshots shared, the error appeared because the UserPrincipalName and DisplayName format in the excel file and the powershell command do not match, please make sure there is no space on both, please refer to the image below:
Take note of the format of the UsePrincipalName and Displayname on the Excel sheet , please make sure you don't leave any space so it matches the PowerShell command, you will have to edit your excel file to look like the image below, don't forget to save the changes after editing for the changes to come into effect:
And run the powershell command below, please edit the path for the csv file, as I included my path when testing, I will highlight were to edit for you;
$Users = Import-Csv C:\Users\Momo\Desktop\PuUser.csv
foreach ($user in $users)
{
$Upn=$user.UserPrincipalName
$Dn=$user.DisplayName
Set-MsolUser -UserPrincipalName $upn -DisplayName $Dn
}
We look forward to hearing from you! Have a lovely weekend!
Sincerely,
Momo | Microsoft Community Moderator
譯本
感謝您的回復。感謝您分享螢幕截圖。
參考共用的螢幕截圖,由於Excel檔中的用戶原則名稱和顯示名稱格式與電源外殼命令不匹配,因此出現了錯誤,請確保兩者上都沒有空格,請參閱下圖:
請注意Excel工作表上使用原則名稱和顯示名稱的格式,請確保您沒有留下任何空間以匹配PowerShell命令,您將必須編輯Excel檔以使其類似於下圖,不要忘記在編輯后保存更改以使更改生效:
並運行下面的powershell命令,請編輯csv文件的路徑,因為我在測試時包括了我的路徑,我將突出顯示為您編輯;
$Users = Import-Csv C:\Users\Momo\Desktop\PuUser.csv
foreach ($user in $users)
{
$Upn=$user.UserPrincipalName
$Dn=$user.DisplayName
Set-MsolUser -UserPrincipalName $upn -DisplayName $Dn
}
我們期待您的回音!祝你週末愉快!
真誠地
莫莫|微軟社區版主
試過十分成功,謝謝你
請問加多個 FirstName ,請問是不是以下寫法:
$Users = Import-Csv C:\Users\Momo\Desktop\PuUser.csv
foreach ($user in $users)
{
$Upn=$user.UserPrincipalName
$Dn=$user.DisplayName
$Fn=$user.FirstName
Set-MsolUser -UserPrincipalName $upn -DisplayName $Dn -FirstName $Fn
}
Thanks