簡體   English   中英

通過 powershell 獲取 Azure ADusers

[英]GET Azure ADusers through powershell

我能夠在 C# 控制台應用程序中獲取 AD 用戶,但我無法通過 powershell 獲取 AD 用戶。 下面是 C# 代碼:

string responseString = null;
using (var client=new HttpClient())
{
    var data = new Dictionary<string, string>
    {
        { "grant_type", "password" },
        { "client_id", "client_id" },
        { "client_secret", "client_secret" },
        { "scope", "https://graph.microsoft.com/.default" },
        { "userName", Your username here },
        { "password", Your password here }
    };
    var content = new FormUrlEncodedContent(data);
    var response = await client.PostAsync("https://login.microsoftonline.com/id/oauth2/v2.0/token", content);
    responseString = await response.Content.ReadAsStringAsync();
}
var token= JsonSerializer.Deserialize<TokenClass>(responseString);
            
var graphapistring = "https://graph.microsoft.com/v1.0/users/";
using (var client1 = new HttpClient())
{
    client1.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token);

    var response = await client1.GetAsync(graphapistring);
    responseString = await response.Content.ReadAsStringAsync();
}
var user= JsonSerializer.Deserialize<userdetails>(responseString);

我需要幫助將上述代碼轉換為 powershell。

根據您的要求,您只需要在 powershell 中使用AzureAD模塊。

通過在 powershell 中運行以下命令來安裝AzureAD模塊: Install-Module AzureAD 你可以參考這個文檔

安裝模塊后,我們需要先連接到azure ad。 運行Connect-AzureAD命令進行連接。

然后你可以通過運行Get-AzureADUser命令來獲取 AD 用戶,這個命令只能響應每個用戶的幾個字段。 如果需要每個用戶的更多字段,可以運行Get-AzureADUser | fl Get-AzureADUser | fl

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM