< Back

Invoke-AzureUtilRestMethod

Sat Jan 11, 2020 12:20 pm

NAME Invoke-AzureUtilRestMethod



SYNOPSIS

Sends an HTTP or HTTPS request as Azure REST API without application registration on Azure AD.





SYNTAX

Invoke-AzureUtilRestMethod [[-Method] {Default | Get | Head | Post | Put | Delete | Trace | Options | Merge |

Patch}] [-Uri] <Uri> [[-AdditionalHeaders] <IDictionary>] [[-ContentType] <String>] [[-Body] <Object>]

[<CommonParameters>]





DESCRIPTION

The Invoke-AzureUtilRestMethod cmdlet sends HTTP and HTTPS requests to Azure REST API service endpoints without

application registration on Azure AD. This cmdlet is very handy for Azure REST API quick testing.





PARAMETERS

-Method

Specifies the method used for the web request. This parameter is optional. The default value is "Get".



Required? false

Position? 1

Default value Get

Accept pipeline input? false

Accept wildcard characters? false



-Uri <Uri>

Specifies the URI of the Azure REST API to which the web request is sent.



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-AdditionalHeaders <IDictionary>

Specifies the additional headers of the web request. Enter a hash table or dictionary. This parameter is

optional.



Required? false

Position? 3

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ContentType <String>

Specifies the content type of the web request. This parameter is optional. The default value is

"application/json".



Required? false

Position? 4

Default value application/json

Accept pipeline input? false

Accept wildcard characters? false



-Body <Object>

Specifies the body of the web request. The body is the content of the web request that follows the headers.

This parameter is optional.



Required? false

Position? 5

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$result = Invoke-AzureUtilRestMethod -Uri 'https://management.azure.com/subscripti ... x-xxxx-xxx

x-xxxxxxxxxxxx/resourcegroups/Sample-RG?api-version=2017-05-10'



PS C:\\>$result.Content

{"id":"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/Sample-RG","name":"Sample-RG","location":

"japaneast","properties":{"provisioningState":"Succeeded"}}



PS C:\\>ConvertFrom-Json $result.Content | Format-Custom

class PSCustomObject

{

id = /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/Sample-RG

name = Sample-RG

location = japaneast

properties =

class PSCustomObject

{

provisioningState = Succeeded

}

}



---- Example Description ----

In this example, get the "Sample-RG" resource group information using Azure REST API. You can find this REST API

details at https://docs.microsoft.com/en-us/rest/a ... Groups_Get.









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>$result = Invoke-AzureUtilRestMethod -Method Head -Uri 'https://management.azure.com/subscriptions/xxxxxxxx-

xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/Sample-RG?api-version=2017-05-10'



PS C:\\>$result.StatusCode

204



---- Example Description ----

In this example, checks whether the "Sample-RG" resource group exists using Azure REST API. This REST API is

return the 204 as HTTP status code if that resource group is exists. You can find this REST API details at

https://docs.microsoft.com/en-us/rest/a ... kExistence.









-------------------------- EXAMPLE 3 --------------------------



PS C:\\>$body = @'



{

"resources": [ "*" ],

"options": "IncludeParameterDefaultValue, IncludeComments"

}

'@



PS C:\\>$result = Invoke-AzureUtilRestMethod -Method Post -Uri 'https://management.azure.com/subscriptions/xxxxxxxx-

xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/Sample-RG/exportTemplate?api-version=2017-05-10' -Body $body



PS C:\\>$result.Content

{"template":{"$schema":"https://schema.management.azure.com/sch ... "contentVe

rsion":"1.0.0.0","parameters":{"storageAccounts_abcd1234_name":{"defaultValue":"abcd1234","type":"String"}},"variab

les":{},"resources":[{"comments":"Generalized from resource: '/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/r

esourceGroups/sample-rg/providers/Microsoft.Storage/storageAccounts/abcd1234'.","type":"Microsoft.Storage/storageAc

counts","sku":{"name":"Standard_LRS","tier":"Standard"},"kind":"Storage","name":"[parameters('storageAccounts_abcd1

234_name')]","apiVersion":"2016-01-01","location":"japaneast","tags":{},"scale":null,"properties":{},"dependsOn":[]

}]}}



---- Example Description ----

In this example, capture the "Sample-RG" resource group as a template. You can find this REST API details at

https://docs.microsoft.com/en-us/rest/a ... rtTemplate.









-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Invoke-AzureUtilRestMethod -Uri

'/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/Sample-RG?api-version=2017-05-10'



---- Example Description ----

In this example, get the "Sample-RG" resource group information using Azure REST API with abbreviated URI. This

cmdlet is automaticaly prepend "https://management.azure.com" to URI if Uri parameter starts with

"/subscriptions/".











RELATED LINKS

PowerShell Gallery: https://www.powershellgallery.com/packages/AzureUtil/

GitHub: https://github.com/tksh164/AzureUtil-PowerShellModule

Azure REST API Reference: https://docs.microsoft.com/en-us/rest/api/