< Back

Invoke-NsxWebRequest

Sat Jan 18, 2020 9:14 pm

NAME Invoke-NsxWebRequest



SYNOPSIS

Constructs and performs a valid NSX REST call and returns a response object

including response headers.





SYNTAX

Invoke-NsxWebRequest [-method <String>] [-URI <String>] [-body <String>] [-connection <PSObject>] [-extraheader

<Hashtable>] [-Timeout <Int32>] [<CommonParameters>]



Invoke-NsxWebRequest -cred <PSCredential> -server <String> -port <Int32> -protocol <String> -UriPrefix <String>

-ValidateCertificate <Boolean> -method <String> -URI <String> [-body <String>] [<CommonParameters>]





DESCRIPTION

Invoke-NsxWebRequest uses either a specified connection object as returned

by Connect-NsxServer, or the $DefaultNsxConnection global variable if

defined to construct a REST api call to the NSX API.



Invoke-NsxWebRequest constructs the appropriate request headers required by

the NSX API, including authentication details (built from the connection

object), required content type and includes any custom headers specified by

the caller that might be required by a specific API resource, before making

the rest call and returning the resulting response object to the caller.



The Response object includes the response headers unlike

Invoke-NsxRestMethod.





PARAMETERS

-cred <PSCredential>

PSCredential object containing authentication details to be used for connection to NSX Manager API



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-server <String>

NSX Manager ip address or FQDN



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-port <Int32>

TCP Port on -server to connect to



Required? true

Position? named

Default value 0

Accept pipeline input? false

Accept wildcard characters? false



-protocol <String>

Protocol - HTTP/HTTPS



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-UriPrefix <String>

URI prefix to support URI rewrite scenario



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ValidateCertificate <Boolean>

Validates the certificate presented by NSX Manager for HTTPS connections



Required? true

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-method <String>

REST method of call. Get, Put, Post, Delete, Patch etc



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-URI <String>

URI of resource (/api/1.0/myresource). Should not include protocol, server or port.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-body <String>

Content to be sent to server when method is Put/Post/Patch



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-connection <PSObject>

Pre-populated connection object as returned by Connect-NsxServer



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-extraheader <Hashtable>

Hashtable collection of KV pairs representing additional headers to send to the NSX Manager during REST call



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Timeout <Int32>

Request timeout value - passed directly to underlying invoke-restmethod call



Required? false

Position? named

Default value 600

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:\\>$MyConnection = Connect-NsxServer -Server OtherNsxManager -DefaultConnection:$false



$response = invoke-nsxwebrequest -method "post" -uri $URI -body $body -connection $MyConnection

$edgeId = $response.Headers.Location.split("/")[$response.Headers.Location.split("/").GetUpperBound(0)]



Creates a connection variable for a non default NSX server, performs a 'Post'

against the URI $URI and then retrieves details from the Location header

included in the response object.











RELATED LINKS