Skip to content

rafamarrara/Get-AzVMContainerID

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

Get-AzVMContainerId 😁

Some PowerShell examples on how to reach out to Azure WireServer from a VM or VMSS instance to get the ContainerId from Azure platform.

Get-AzVMContainerId

Using Invoke-RestMethod

$uri = 'http://168.63.129.16/machine?comp=goalstate'
$headers = @{
    "x-ms-guest-agent-name" = "WaAgent-2.5.0.0 (2.7.0.0)"
    "x-ms-version" = "2015-04-05"
}
$xml = $null
$xml = Invoke-RestMethod -Uri $uri -Headers $headers
$xml.GoalState.Container.ContainerId

Using System.Net.WebClient

$uri = 'http://168.63.129.16/machine?comp=goalstate'
$wc = New-Object System.Net.WebClient 
$wc.Headers.Add("x-ms-guest-agent-name", "WaAgent-2.5.0.0 (2.7.0.0)")
$wc.Headers.Add("x-ms-version", "2015-04-05")
$xml = $null
$xml = [xml]$wc.DownloadString($uri)
$xml.GoalState.Container.ContainerId

Using MSXML2.ServerXMLHTTP

$objXmlHttp = New-Object -ComObject MSXML2.ServerXMLHTTP
$uri = 'http://168.63.129.16/machine?comp=goalstate'
$objXmlHttp.Open("GET", $uri, $false)
$objXmlHttp.setRequestHeader("x-ms-guest-agent-name", "WaAgent-2.5.0.0 (2.7.0.0)")
$objXmlHttp.setRequestHeader("x-ms-version", "2015-04-05")
$objXmlHttp.Send()
$xml = $null
$xml = [xml]$objXmlHttp.responseText
$xml.GoalState.Container.ContainerId
Good to know 🦉

... ServerXMLHTTP object depends on WinHTTP proxy settings ...

ServerXMLHTTP + WinHTTP Proxy

About

Code to reach out to Azure WireServer and get current ContainerID where the VM or VMSS instance is running

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors