$menu = @( "https://management.azure.com/subscriptions?api-version=2016-06-01", "https://management.azure.com/subscriptions/{subscriptionid}/resourcegroups?api-version=2021-04-01", "https://management.azure.com/subscriptions/{subscriptionid}/providers/Microsoft.Compute/virtualMachines?api-version=2024-07-01", "Enter custom uri" ) $i = 0 foreach ($item in $menu) { $menuitem = [string]($i+1) + ") " + $item Write-Host $menuitem $i++ } $outfile = "" $selecteditem = Read-Host "Enter no." $requesturi = $menu[($selecteditem - 1)] if ($requesturi -eq "Enter custom uri") { $requesturi = Read-Host "Enter your uri (you can use keyword {subscriptionid})" } $outfile = Read-Host "Enter ourput to json file(Path)" $clientid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" $clientsecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" $subscriptionid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" $tenantid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" $resource = "https://management.azure.com/" $tokenendpoint = "https://login.microsoftonline.com/$tenantid/oauth2/token" $body = @{ grant_type = "client_credentials" resource = $resource client_id = $clientid client_secret = $clientsecret } $tokenresponse = Invoke-RestMethod -Method Post -Uri $tokenendpoint -Body $body -ContentType "application/x-www-form-urlencoded" $accesstoken = $tokenresponse.access_token $headers = @{ 'Authorization' = "Bearer $accesstoken" 'Content-Type' = 'application/json' } $requesturi = $requesturi | % Replace "{subscriptionid}" $subscriptionid $requesturi = $requesturi | % Replace "{subscriptionId}" $subscriptionid $ret = (Invoke-RestMethod -Uri $requesturi -Headers $headers -Method Get) if ($outfile -ne "") { $ret | ConvertTo-Json -Depth 10 |Set-Content $outfile } Write-Output $ret