次の方法で共有

PowerShellで既存ユーザーのプロパティを修正したいがエラーが出て進まない。

健一 富山 0 評価のポイント
2026-04-20T06:10:10.8+00:00

Get-MgUser_List: DeviceCodeCredential authentication failed: Object reference not set to an instance of an object.

Azure Advisor
Azure Advisor

ユーザーがベスト プラクティスに従って Azure のデプロイを最適化するための、パーソナル設定が行われた Azure のレコメンデーション エンジン。


2 件の回答

並べ替え方法: 最も役に立つ
  1. チャブーン 6,306 評価のポイント MVP ボランティア モデレーター
    2026-04-20T09:26:41.2966667+00:00

    チャブーンです。

    この件ですが、エラーメッセージに答えが書いてあるようですよ。

    Get-MgUser_List: DeviceCodeCredential authentication failed: Object reference not set to an instance of an object.

    これは、connect-mggraph実行時に、デバイスコードによる認証を行わなかったので、(必要な認証が足りず)アクセスできないの意味です。直すためには、認証からやり直す必要があります。

    # デバイスコードによる認証を必須化します。また、ロール権限にかかわらずアクセス許可のスコープは必須です。
    
    Connect-MSGraph -Scopes "User.ReadWrite.All" -UseDeviceAuthentication
    

    これを実行するとプロンプト画面で、以下の表示が出ますので、URL とCODEをメモ(コピー)します。

    To sign in, use a web browser to open the page https://microsoft.com/deveicelogin and enter the code <9桁のコード文字> to authenticate.
    

    このあと、プロンプト画面は開いたまま、ブラウザを起動し、以下を入力します。

    うまくいくと、プロンプト画面で認証が成功し、接続情報等が表示されるはずです。この段階でブラウザは閉じて問題ありません(これ以降は使いません)。以下のページも確認してください。

    How to use Connect-MgGraph – All Options

    ("Device code"の項目を見てください)


  2. 健一 富山 0 評価のポイント
    2026-04-20T07:53:02.88+00:00

    Get-MgUser -All -Property UserPrincipalName,DisplayName,GivenName,Surname,OfficeLocation,JobTitle |

    Select UserPrincipalName,DisplayName,GivenName,Surname,OfficeLocation,JobTitle |

    Export-Csv "C:\temp\UserList.csv" -Encoding UTF8 -NoTypeInformation

    Get-MgUser_List: DeviceCodeCredential authentication failed: Object reference not set to an instance of an object.

    0 件のコメント コメントはありません

お客様の回答

質問作成者は回答に "承認済み"、モデレーターは "おすすめ" とマークできます。これにより、ユーザーは作成者の問題が回答によって解決したことを把握できます。