【发布时间】:2021-01-26 17:10:31
【问题描述】:
我能够在 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。
【问题讨论】:
-
您好,请参考我下面提供的解决方案。如果它对您的问题有帮助,请accept它作为答案(单击我的答案旁边的复选标记,将其从灰色切换为已填充)。先谢谢了~
-
如果还有什么问题,请告诉我。
标签: .net powershell active-directory azure-active-directory azure-powershell