Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 在不调用azuread(获取AzureADUserMembership)的情况下检查登录用户的组成员资格或职务_Powershell_Azure Active Directory - Fatal编程技术网

Powershell 在不调用azuread(获取AzureADUserMembership)的情况下检查登录用户的组成员资格或职务

Powershell 在不调用azuread(获取AzureADUserMembership)的情况下检查登录用户的组成员资格或职务,powershell,azure-active-directory,Powershell,Azure Active Directory,我正在和一位同事编写脚本。此脚本将显示一个弹出窗口。 我们希望此弹出窗口仅显示给特定的用户组(教师而不是学生)。所以我们要检查用户的组成员资格。由于此脚本将在本地计算机上安装,因此我们不希望在所有计算机上安装azuread cmdlet,也不希望将azure ad凭据传递给脚本 所以我们想知道他们的azure广告信息是否存储在本地计算机上。还有我们是否可以通过powershell访问它?(如果我们能得到用户的jobtitle,也会很有帮助) 也欢迎其他想法。您正在寻找的与信息相关的用户不太可能存

我正在和一位同事编写脚本。此脚本将显示一个弹出窗口。 我们希望此弹出窗口仅显示给特定的用户组(教师而不是学生)。所以我们要检查用户的组成员资格。由于此脚本将在本地计算机上安装,因此我们不希望在所有计算机上安装azuread cmdlet,也不希望将azure ad凭据传递给脚本

所以我们想知道他们的azure广告信息是否存储在本地计算机上。还有我们是否可以通过powershell访问它?(如果我们能得到用户的jobtitle,也会很有帮助)


也欢迎其他想法。

您正在寻找的与信息相关的用户不太可能存储在本地

因此,为了满足您的要求,您必须有一些方法与Azure AD进行通信。您的要求是不使用任何其他库和使用PowerShell

GraphAPI可以派上用场

为防止用户干预,您可以对应用程序使用仅应用程序图形权限。 您可以参考本文了解更多应用程序注册、客户端机密和应用程序权限:

您从PowerShell使用图形端点,并从Azure AD获取已登录用户的必要详细信息,而无需外部库

#Acquiring the graph token
$web="https://login.microsoftonline.com/<TENANT ID>/oauth2/v2.0/token"
$body = "client_id=<CLIENT ID>&scope=https://graph.microsoft.com/.default&client_secret=<CLIENTSECRET>&grant_type=client_credentials"
$response = Invoke-WebRequest $web -Body $body -Method Post
$token = ($response | ConvertFrom-Json).access_token

#Getting the logged username that will be used in the graph api
$upn = $env:USERNAME + "@" + $env:USERDNSDOMAIN


#building the authorization header
$header = @{"Authorization" = " Bearer $token"}

#gettting the user details
$content = Invoke-WebRequest "https://graph.microsoft.com/v1.0/users/$upn" -Headers $header -Method Get
$details = $content.Content | ConvertFrom-Json

#getting the group membership
$content =  Invoke-WebRequest "https://graph.microsoft.com/v1.0/users/$upn/memberof" -Headers $header -Method Get
$groupdetails = ($content.Content | ConvertFrom-Json).value
#获取图形标记
$web=”https://login.microsoftonline.com//oauth2/v2.0/token"
$body=“client\u id=&scope=https://graph.microsoft.com/.default&client_secret=&grant_type=client_credentials"
$response=Invoke WebRequest$web-Body$Body-Method Post
$token=($response | convertfromjson)。访问_令牌
#获取将在graph api中使用的已记录用户名
$upn=$env:USERNAME+“@”+$env:USERDNSDOMAIN
#构建授权标头
$header=@{“授权”=“持有人$token”}
#获取用户详细信息
$content=调用WebRequest“https://graph.microsoft.com/v1.0/users/$upn”-Headers$header-方法Get
$details=$content.content |从Json转换
#获取组成员资格
$content=调用WebRequest“https://graph.microsoft.com/v1.0/users/$upn/memberof“-Headers$header-方法Get
$groupdetails=($content.content | ConvertFrom Json).value

<代码>请考虑接受这个解决方案: