Skip to content

Instantly share code, notes, and snippets.

@ljtill
Last active October 4, 2018 21:55
Show Gist options
  • Select an option

  • Save ljtill/2c7a9a1538d56bea2c29068f961556fc to your computer and use it in GitHub Desktop.

Select an option

Save ljtill/2c7a9a1538d56bea2c29068f961556fc to your computer and use it in GitHub Desktop.
Provides the ability to retrieve Virtual Machines via REST API
function Get-AzureRmVirtualMachines {
<#
.SYNOPSIS
Get-AzureRmVirtualMachines will retrieve all Virtual Machines within a Subscription.
.DESCRIPTION
Provides the ability to retrieve all Virtual Machines from a specific Subscription Id via REST API.
.EXAMPLE
Get-AzureRmVirtualMachines -SubscriptionId $subscriptionId -AccessToken $accessToken.
.LINK
https://gist.github.com/ljtill
#>
[CmdletBinding()]
param (
[Parameter()]
[string]$SubscriptionId,
[Parameter()]
[string]$AccessToken
)
begin {
$apiVersion = "2017-12-01"
$request = @{
Method = "GET"
Url = ("https://management.azure.com/subscriptions/" + $subscriptionId + "/providers/Microsoft.Compute/virtualmachines?api-version=" + $apiVersion)
Headers = @{
"Authorization" = ("Bearer " + $accessToken)
"Accept" = "application/json"
}
Body = $null
}
}
process {
$response = Invoke-RestMethod @request
}
end {
return $response.value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment