gpt4 book ai didi

azure - 使用 PowerShell 5+ 的 Azure 应用程序列表、创建日期、权限和 2FA 设置

转载 作者:行者123 更新时间:2023-12-03 02:51:14 24 4
gpt4 key购买 nike

我是 Azure 和 powershell 的新手。我对两者都有一些非常基本的知识和一些脚本编写经验,但不是在 powershell 中。目标:从 Azure 获取应用程序列表以及所有可用的相关信息。具体来说是创建日期。 CSV 格式的输出..过去 60 天内创建的应用程序

https://learn.microsoft.com/en-us/powershell/module/azurerm.resources/get-azurermadapplication?view=azurermps-6.13.0我根本不需要工作,但这似乎是我想要的。

$ClientID     = "XCXXXXXXXXXXXXXXXX"
$ClientSecret = "XCXXXXXXXXXXXXXXXX"
$tenantdomain = "XCXXXXXXXXXXXXXXXX"
$loginURL = "XCXXXXXXXXXXXXXXXX"
$resource = "https://graph.microsoft.com"
$path = "C:\Scripts\objects.csv"
$headers = "App Name,CreatedOn"

# body for the rest request to get an access token
$body = @{grant_type="client_credentials";resource=$resource;client_id=$ClientID;client_secret=$ClientSecret}

# get an access token
$oauth = Invoke-RestMethod -Method Post -Uri $loginURL/$tenantdomain/oauth2/token?api-version=1.0 -Body $body

# if we have an access token, then make the graph call
if ($oauth.access_token -ne $null) 

{

    $headerParams = @{'Authorization'="$($oauth.token_type) $($oauth.access_token)"}

    $url = "https://graph.microsoft.com/beta/applications?select=createddatetime,displayname"


    do {


        $response = Invoke-WebRequest -Uri $url -UseBasicParsing -Headers $headerParams -Method GET  -ContentType "application/json"
        if ($response.Content)
        {

最佳答案

您提到的旧 AzureRm powershell Get-AzureRmADApplication 本质上调用的是 azure ad graph api,在 azure ad graph api 中,application entity没有您想要的 createddatetime 属性。此外,新的 Az powershell Get-AzADApplication 和 azure ad powershell Get-AzureADApplication 也会调用 azure ad graph API,因此无法满足您的要求。

您的脚本是一种解决方法,该脚本使用客户端凭据流来获取访问 token 并使用该 token 调用 Microsoft graph API,逻辑应该是正确的。

由于您没有提供有关脚本的一些错误信息,我只能给您一个示例,它在我这边工作得很好。

首先,在获取访问 token 之前,请确保您已授予广告应用的 Microsoft Graph API 权限。导航到门户中的 Azure Active Directory -> 应用注册 -> 找到您的广告应用 -> API 权限 -> 添加a 权限 -> 添加 Microsoft graph api 的Application 权限(权限可以是 Application.ReadWrite.All, Directory.Read.All 从最低权限到最高权限,请参阅 List applications Permissions ) -> 添加权限 -> 最后,不要忘记单击授予管理员同意 按钮。

enter image description here

我的示例(示例是在获取访问 token 并使用它调用 MS garph api 之后):

$url = "https://graph.microsoft.com/beta/applications?select=createddatetime,displayname"
$accesstoken = "eyJ0eXAxxxxxxeHB1Y3FuQktJR2Nyx9Cg"
$header = @{
'Authorization' = 'Bearer ' + $accesstoken
}

$response = Invoke-RestMethod –Uri $url –Headers $header –Method GET
$response.value | Export-Csv -Path "C:\Users\joyw\Desktop\testfile.csv" -NoTypeInformation

enter image description here

关于azure - 使用 PowerShell 5+ 的 Azure 应用程序列表、创建日期、权限和 2FA 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56027873/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com