View Attach-PortForwardLoadBalancer.ps1
This file contains 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
# authentication using service principal (appid+secret) | |
$tenantid = '<tenant-id>'; | |
$appid = '<app-id>'; | |
$secret = ConvertTo-SecureString '<app-secret>' -AsPlainText -Force; | |
$cred = New-Object System.Management.Automation.PSCredential ($appid, $secret); | |
Login-AzAccount -ServicePrincipal -TenantId $tenantid -Credential $cred | |
# if login does not succeed with service principal then prompt for login | |
if ([string]::IsNullOrEmpty($(Get-AzureRmContext).Account)) {Login-AzureRmAccount} |
View azure-metadata-service-2.ps1
This file contains 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 for easily querying the Azure Instance Metadata Service | |
Function AzMeta { | |
Param( [Parameter(ValueFromPipeline)] $p ) | |
Invoke-RestMethod ` | |
-Headers @{"Metadata"="true"} ` | |
-URI "http://169.254.169.254/metadata/instance/$($p)?api-version=2017-08-01&format=text" | |
} |
View azure-metadata-service-1.ps1
This file contains 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
# “One-liner” for easily querying the Azure Instance Metadata Service. | |
"network/interface/0/ipv4/ipAddress/0/publicIpAddress" | Tee-Object -Variable p | Out-Null ; Invoke-RestMethod -Headers @{"Metadata"="true"} -URI "http://169.254.169.254/metadata/instance/$($p)?api-version=2017-08-01&format=text" | |
# Instead of "network/interface/0/ipv4/ipAddress/0/publicIpAddress" you can use any | |
# path throgh the instance metadata json structure. | |
# You can find a sample json structure here: | |
# { | |
# "compute": { | |
# "location": "westus2", |