< Back

Get-GceMetadata

Mon Jan 13, 2020 11:13 pm

NAME Get-GceMetadata



SYNOPSIS

Gets the current metadata from the metadata server.





SYNTAX

Get-GceMetadata [-Path <string>] [-Recurse <SwitchParameter>] [-AppendETag <SwitchParameter>] [-WaitUpdate

<SwitchParameter>] [-LastETag <string>] [-Timeout <TimeSpan>] [<CommonParameters>]





DESCRIPTION

Gets the current metadata from the metadata server. Get-GceMetadata can only be called from a Google Compute

Engine VM instance. Calls from any other machine will fail.





PARAMETERS

-Path <string>

The path to the specific metadata you wish to get e.g. "instance/tags", "instance/attributes",

"project/attributes/sshKeys".



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Recurse <SwitchParameter>

If set, will get the metadata subtree as a JSON string. If -Path is not set, will get the entire metadata tree

as a JSON string.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-AppendETag <SwitchParameter>

When set, the value of the respone ETag will be appended to the output pipeline after the content.



"$metadata, $etag = Get-GceMetadata -AppendETag -Recurse" gets the entire metadata tree, and the ETag of the

version retrieved.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-WaitUpdate <SwitchParameter>

If true, the query will wait for the metadata to update.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-LastETag <string>

The last ETag known. Used in conjunction with -WaitUpdate. If the last ETag does not match the current ETag of

the metadata server, it will return the updated value immediatly.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Timeout <TimeSpan>

Used in conjunction with -WaitUpdate. The amout of time to wait. If the timeout expires, the current metadata

will be returned.



Check the ETag using AppendEtag to see if the data was updated within the timeout period.



Required? false

Position? named

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

System.String





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



PS C:\\> $allMetadata = Get-GceMetadata -Recurse | ConvertFrom-Json



Gets all of the metadata and converts it from the given JSON to a PSCustomObject.

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



PS C:\\> $hostName = Get-GceMetadata -Path "instance/hostname"



Gets the hostname of the instance.

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



PS C:\\> $customProjectMetadata = Get-GceMetadata -Path "project/attributes/customKey"



Gets the value of the custom metadata with key "customKey" placed in the project .

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



PS C:\\> $metadata, $etag = Get-GceMetadata -AppendETag -Recurse



Gets the entire metadata tree, and the ETag of the version retrieved.

---------- EXAMPLE 5 ----------



PS C:\\> $newTags, $newEtag = Get-GceMetadata -Path "instance/tags" -AppendETag -WaitUpdate `

-LastETag $oldETag



Waits for the metadata "instance/tags" to be updated by the server.



RELATED LINKS

[Metadata Documentation] (https://cloud.google.com/compute/docs/s ... g-metadata)

[Metadata server documentation] (https://cloud.google.com/compute/docs/s ... g-metadata)