Last active
October 4, 2018 21:55
-
-
Save ljtill/2c7a9a1538d56bea2c29068f961556fc to your computer and use it in GitHub Desktop.
Provides the ability to retrieve Virtual Machines via REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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