用 command shell 大量修改 o365 用戶資料,未能成功

匿名
2022-09-23T03:03:27+00:00

用 o365 command shell 大量修改用戶資料,未能成功,不知還差乜?謝謝

Microsoft 365 與 Office | 安裝、兌換、啟動 | 教育版 | Windows

鎖定的問題。 此問題已從 Microsoft 支援服務社群移轉。 您可以對其是否有幫助進行投票,但無法對問題新增註解或回覆,或進行追蹤。

0 則留言 沒有留言

9 個回答

排序依據: 最實用
  1. 匿名
    2022-09-27T23:14:37+00:00

    Dear Mr Lo Yun Lun

    早晨! 感謝您的回應。

    對遲到嘅回應表示歉意。

    要回答您的查詢,是的,該命令是正確的。

    很高興為您提供幫助,如果您有任何其他疑問,請隨時告訴我們。

    祝你生活愉快!

    誠心誠意

    Momo| Microsoft Community Moderator

    此回答有幫助嗎?

    0 則留言 沒有留言
  2. 匿名
    2022-09-26T03:19:51+00:00

    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

    此回答有幫助嗎?

    0 則留言 沒有留言
  3. 匿名
    2022-09-24T10:07:04+00:00

    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

    }

    我們期待您的回音!祝你週末愉快!

    真誠地

    莫莫|微軟社區版主

    此回答有幫助嗎?

    0 則留言 沒有留言
  4. 匿名
    2022-09-24T01:38:48+00:00

    o365f1student.csv file format

    此回答有幫助嗎?

    0 則留言 沒有留言
  5. 匿名
    2022-09-23T11:35:59+00:00

    Dear Mr Lo Yun Lung

    Thank you for posting in the Microsoft Community. We are happy to provide you with help.

    Please note that our team will respond to your inquiry in English, you can publish your response in your native language and we will translate it in-house. Thank you for your understanding.

    Based on the screenshot shared the error message is due to null instance in each loop, the Azure AD is not able to identify objects to commit new changes to.

    Please check if running the following command returns any result before executing for each loop, and check to see if any error is presented. ( You may share screenshots here of your tests).

    Get-MsolUser -UserPrincipalName ******@domain.com

    I'd also like to confirm if the initial users have been created already and only new information is being added? If not then please try to run : New-MsolUser

    The above command is to be run only if users haven't already been created, if that’s not the case please skip this step no need to run that command.

    Lastly please run the following command and share results with us :

    $users = Import-Csv C:\Temp\o365f1student.csv

    Foreach($user in $users){ Set-MsolUser -UserPrincipalName $user. UserPrincipalName -DisplayName $user. DisplayName }

    Please understand that sometimes our first answer may not solve the problem right away. It depends on what information we get in the thread and the complexity of the question. But through your cooperation, we can find a solution together.

    We look forward to hearing from you.

    In good faith

    Momo | Microsoft Community Moderator

    Dear Mr Lo Yun Lung

    Thank you for posting in the Microsoft Community. We are happy to provide you with help.

    Based on the screenshot from the share, the error message is that Azure AD does not recognize the object to commit the new changes to because of an empty instance in each loop.

    Before executing each loop, check to see if running the following command returns any results and check for any errors. (You can share a screenshot of the test here).

    ***Get-MsolUser -UserPrincipalName ***@domain.com

    I also want to confirm that the initial user has been created and only new information has been added? If not, try running: New-MsolUser

    Run the above command only if the user has not been created, if this is not the case, skip this step and do not need to run the command.

    Finally, please run the following command and share the results with us:

    $users = Import-Csv C:\Temp\o365f1student.csv

    Foreach($user in $users){ Set-MsolUser -UserPrincipalName $user. UserPrincipalName -DisplayName $user. DisplayName }

    Please understand that sometimes our first answer may not solve the problem immediately. It depends on the information we get in the thread and the complexity of the problem. But through your cooperation, we can find solutions together.

    We look forward to hearing from you.

    In good faith

    Momo | Microsoft Community Moderator

    此回答有幫助嗎?

    0 則留言 沒有留言