[go: nahoru, domu]

Skip to content

Commit

Permalink
Add Get-AllAzureRMVirtualMachines
Browse files Browse the repository at this point in the history
  • Loading branch information
andyrobbins committed Aug 8, 2022
1 parent 50852db commit 259e56f
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions BARK.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4815,6 +4815,76 @@ Function Get-AllAzureRMResourceGroups {

}

Function Get-AllAzureRMVirtualMachines {
<#
.SYNOPSIS
Retrieves all JSON-formatted Azure RM virtual machine objects under a particular subscription using the Azure management API
Author: Andy Robbins (@_wald0)
License: GPLv3
Required Dependencies: None
.DESCRIPTION
Retrieves all JSON-formatted Azure RM virtual machine objects under a particular subscription using the Azure management API
.PARAMETER Token
The AzureRM-scoped JWT for the user with the ability to list virtual machines
.PARAMETER SubscriptionID
The unique identifier of the subscription you want to list virtual machines under
.EXAMPLE
C:\PS> $VirtualMachines = Get-AllAzureRMVirtualMachines -Token $Token -SubscriptionID "839df4bc-5ac7-441d-bb5d-26d34bca9ea4"
Description
-----------
Uses the JWT in the $Token variable to list all virtual machines under the subscription with ID starting with "839..." and put them into the $VirtualMachines variable
.LINK
https://medium.com/p/74aee1006f48
#>
[CmdletBinding()] Param (
[Parameter(
Mandatory = $True,
ValueFromPipeline = $True,
ValueFromPipelineByPropertyName = $True
)]
[String]
$Token,

[Parameter(
Mandatory = $True,
ValueFromPipeline = $True,
ValueFromPipelineByPropertyName = $True
)]
[String]
$SubscriptionID
)

# Get all Virtual Machines under a specified subscription
$URI = "https://management.azure.com/subscriptions/$($SubscriptionID)/providers/Microsoft.Compute/virtualMachines?api-version=2022-03-01"
$Results = $null
do {
$Results = Invoke-RestMethod `
-Headers @{
Authorization = "Bearer $($Token)"
} `
-URI $URI `
-UseBasicParsing `
-Method "GET" `
-ContentType "application/json"
if ($Results.value) {
$VirtualMachineObjects += $Results.value
} else {
$VirtualMachineObjects += $Results
}
$uri = $Results.'@odata.nextlink'
} until (!($uri))

$VirtualMachineObjects

}

Function ConvertTo-Markdown {
<#
.Synopsis
Expand Down

0 comments on commit 259e56f

Please sign in to comment.