Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Note: this module is not in any way developed or supported by anyone officially
### vRealize Orchestrator

||||
| --- | --- | --- |
|6.1|7.0|7.0.1|
| --- | --- | --- | --- |
|6.1|7.0|7.0.1| 8.X |

### PowerShell Editions

Expand All @@ -24,7 +24,7 @@ Note: this module is not in any way developed or supported by anyone officially

## Authentication

Currently PowervRO only supports basic Authentication. If you are using one of the other supported methods let us know.
Currently PowervRO only supports basic and token Authentication. If you are using one of the other supported methods let us know.

## Download

Expand Down
137 changes: 113 additions & 24 deletions src/Functions/Public/Connect-vROServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
.PARAMETER Credential
Credential object to connect with

.PARAMETER TokenAuth
Use Token Authentication instead of Basic Authentication. This is only available in vRO 8.x and above

.PARAMETER IgnoreCertRequirements
Ignore requirements to use fully signed certificates

Expand Down Expand Up @@ -50,6 +53,9 @@
.EXAMPLE
Connect-vROServer -Server vro01.domain.local -Port 443 -Credential (Get-Credential)

.EXAMPLE
Connect-vROServer -Server vro01.domain.local -Port 443 -Credential (Get-Credential) -TokenAuth

#>
[CmdletBinding(DefaultParametersetName="Username")][OutputType('System.Management.Automation.PSObject')]

Expand All @@ -75,6 +81,9 @@
[ValidateNotNullOrEmpty()]
[Management.Automation.PSCredential]$Credential,

[Parameter(Mandatory=$false)]
[Switch]$TokenAuth,

[Parameter(Mandatory=$false)]
[Switch]$IgnoreCertRequirements,

Expand Down Expand Up @@ -174,34 +183,114 @@

try {

# --- Set Encoded Password
$Auth = $Username + ':' + $ConnectionPassword
$Encoded = [System.Text.Encoding]::UTF8.GetBytes($Auth)
$EncodedPassword = [System.Convert]::ToBase64String($Encoded)

# --- Create Output Object
$Script:vROConnection = [pscustomobject]@{

Server = "https://$($Server):$($Port)"
Username = $Username
EncodedPassword = $EncodedPassword
Version = $Null
APIVersion = $Null
SignedCertificates = $SignedCertificates
SslProtocol = $SslProtocolResult
if (!$TokenAuth)
{
# --- Set Encoded Password
$Auth = $Username + ':' + $ConnectionPassword
$Encoded = [System.Text.Encoding]::UTF8.GetBytes($Auth)
$EncodedPassword = [System.Convert]::ToBase64String($Encoded)

# --- Create Output Object
$Script:vROConnection = [pscustomobject]@{

Server = "https://$($Server):$($Port)"
Username = $Username
EncodedPassword = $EncodedPassword
Version = $Null
APIVersion = $Null
SignedCertificates = $SignedCertificates
SslProtocol = $SslProtocolResult
}

# --- Update vROConnection with version information
$VersionInfo = Get-vROVersion
$Script:vROConnection.Version = $VersionInfo.Version
$Script:vROConnection.APIVersion = $VersionInfo.APIVersion

# --- Test the credentials provided
Write-Verbose -Message "Testing credentials"
$URI = "/vco/api/server/permissions"
Invoke-vRORestMethod -Method Get -URI $URI -ErrorAction Stop | Out-Null

Write-Output $Script:vROConnection
}
else
{

# Create the body for the authentication request
$body = @{
username = $Username
password = $ConnectionPassword
} | ConvertTo-Json -Depth 10

$refresh = @{
uri = "https://$($Server):$($Port)/csp/gateway/am/api/login?access_token"
method = "POST"
body = $body
headers = @{
"Content-Type" = "application/json"
}
}

$refreshToken = (Invoke-RestMethod @refresh -ErrorAction Stop -OutVariable refreshResponse).refresh_token
if ($null -eq $refreshToken) {
Write-Error "Failed to obtain refresh token from vRO server."

# --- Update vROConnection with version information
$VersionInfo = Get-vROVersion
$Script:vROConnection.Version = $VersionInfo.Version
$Script:vROConnection.APIVersion = $VersionInfo.APIVersion
}

# --- Test the credentials provided
Write-Verbose -Message "Testing credentials"
$URI = "/vco/api/server/permissions"
Invoke-vRORestMethod -Method Get -URI $URI -ErrorAction Stop | Out-Null
# Retrieve the access token using the refresh token

$bearerBody = @{
refreshToken = $refreshToken
} | ConvertTo-Json -Depth 10

$bearer = @{
uri = "https://$($Server):$($Port)/iaas/api/login"
method = "POST"
body = $bearerBody
headers = @{
"Content-Type" = "application/json"
}
}

$accessToken = (Invoke-RestMethod @bearer -ErrorAction Stop -OutVariable bearerResponse).token
if ($null -eq $accessToken) {
Write-Error "Failed to obtain access token from vRO server."

}

#prepare headers with bearer token
$headers = @{
Authorization = "Bearer $accessToken"
"Content-Type" = "application/json"
}

Write-Output $Script:vROConnection
# --- Create Output Object
$Script:vROConnection = [pscustomobject]@{

Server = "https://$($Server):$($Port)"
Username = $Username
Token = $accessToken
AuthHeaders = $headers
Version = $Null
APIVersion = $Null
SignedCertificates = $SignedCertificates
SslProtocol = $SslProtocolResult
}

# --- Update vROConnection with version information
$VersionInfo = Get-vROVersion
$Script:vROConnection.Version = $VersionInfo.Version
$Script:vROConnection.APIVersion = $VersionInfo.APIVersion

# --- Test the credentials provided
Write-Verbose -Message "Testing credentials"
$URI = "/vco/api/server/permissions"
Invoke-vRORestMethod -Method Get -URI $URI -ErrorAction Stop | Out-Null

Write-Output $Script:vROConnection

}
}
catch [Exception]{

Expand Down
11 changes: 10 additions & 1 deletion src/Functions/Public/Invoke-vRORestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,16 @@ if (-not $Script:vROConnection){

"Accept"="application/json";
"Content-Type" = "application/json";
"Authorization" = "Basic $($Script:vROConnection.EncodedPassword)";

}

# --- Add the Authorization header
if ($Script:vROConnection.token)
{
$Headers.Add("Authorization", "Bearer $($Script:vROConnection.Token)")
}
else {
$Headers.Add("Authorization", "Basic $($Script:vROConnection.EncodedPassword)")
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/Functions/Public/actions-service/Export-vROAction.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@

$Headers = @{

"Authorization" = "Basic $($Script:vROConnection.EncodedPassword)";
"Accept" ="Application/zip";
"Accept-Encoding" = "gzip, deflate";
"Content-Type" = "Application/zip;charset=utf-8";

}

# --- Add the Authorization header
if ($Script:vROConnection.token)
{
$Headers.Add("Authorization", "Bearer $($Script:vROConnection.Token)")
}
else {
$Headers.Add("Authorization", "Basic $($Script:vROConnection.EncodedPassword)")
}

# --- Run vRO REST Request
$Request = Invoke-vRORestMethod -Uri $URI -Method Get -Headers $Headers -WebRequest -Verbose:$VerbosePreference

Expand Down
10 changes: 9 additions & 1 deletion src/Functions/Public/actions-service/Import-vROAction.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,20 @@
# --- Set custom headers for the request
$Headers = @{

"Authorization" = "Basic $($Script:vROConnection.EncodedPassword)";
"Accept" = "Application/json"
"Accept-Encoding" = "gzip,deflate,sdch";
"Content-Type" = "multipart/form-data; boundary=$($Boundary)"
}

# --- Add the Authorization header
if ($Script:vROConnection.token)
{
$Headers.Add("Authorization", "Bearer $($Script:vROConnection.Token)")
}
else {
$Headers.Add("Authorization", "Basic $($Script:vROConnection.EncodedPassword)")
}

if ($PSCmdlet.ShouldProcess($FileInfo.FullName)){

# --- Run vRO REST Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,21 @@

$Headers = @{

"Authorization" = "Basic $($Script:vROConnection.EncodedPassword)";
"Accept" ="application/vcoobject+xml";
"Accept-Encoding" = "gzip, deflate";
"Content-Type" = "Application/vcoobject+xml;charset=utf-8";

}

# --- Add the Authorization header
if ($Script:vROConnection.token)
{
$Headers.Add("Authorization", "Bearer $($Script:vROConnection.Token)")
}
else {
$Headers.Add("Authorization", "Basic $($Script:vROConnection.EncodedPassword)")
}

# --- Run vRO REST Request
$Request = Invoke-vRORestMethod -Uri $URI -Method Get -Headers $Headers -WebRequest -Verbose:$VerbosePreference

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,20 @@
# --- Set custom headers for the request
$Headers = @{

"Authorization" = "Basic $($Script:vROConnection.EncodedPassword)";
"Accept" = "Application/json"
"Accept-Encoding" = "gzip,deflate,sdch";
"Content-Type" = "multipart/form-data; boundary=$($Boundary)"
}

# --- Add the Authorization header
if ($Script:vROConnection.token)
{
$Headers.Add("Authorization", "Bearer $($Script:vROConnection.Token)")
}
else {
$Headers.Add("Authorization", "Basic $($Script:vROConnection.EncodedPassword)")
}

if ($PSCmdlet.ShouldProcess($FileInfo.FullName)){

# --- Run vRO REST Request
Expand Down
10 changes: 9 additions & 1 deletion src/Functions/Public/packages-service/Export-vROPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,20 @@

$Headers = @{

"Authorization" = "Basic $($Script:vROConnection.EncodedPassword)";
"Accept" ="Application/zip";
"Accept-Encoding" = "gzip, deflate";
"Content-Type" = "Application/zip;charset=utf-8";
}

# --- Add the Authorization header
if ($Script:vROConnection.token)
{
$Headers.Add("Authorization", "Bearer $($Script:vROConnection.Token)")
}
else {
$Headers.Add("Authorization", "Basic $($Script:vROConnection.EncodedPassword)")
}

if ($PSBoundParameters.ContainsKey('DontExportConfigurationAttributeValues')){

$ExportConfigurationAttributeValues = 'false'
Expand Down
11 changes: 9 additions & 2 deletions src/Functions/Public/packages-service/Import-vROPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,20 @@

# --- Set custom headers for the request
$Headers = @{

"Authorization" = "Basic $($Script:vROConnection.EncodedPassword)";
"Accept" = "Application/json"
"Accept-Encoding" = "gzip,deflate,sdch";
"Content-Type" = "multipart/form-data; boundary=$($Boundary)"
}

# --- Add the Authorization header
if ($Script:vROConnection.token)
{
$Headers.Add("Authorization", "Bearer $($Script:vROConnection.Token)")
}
else {
$Headers.Add("Authorization", "Basic $($Script:vROConnection.EncodedPassword)")
}

if ($PSCmdlet.ShouldProcess($FileInfo.FullName)){

# --- Run vRO REST Request
Expand Down
10 changes: 9 additions & 1 deletion src/Functions/Public/plugin-service/Export-vROPlugin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,20 @@

$Headers = @{

"Authorization" = "Basic $($Script:vROConnection.EncodedPassword)";
"Accept" ="Application/json";
"Content-Type" = "application/zip;charset=UTF-8";

}

# --- Add the Authorization header
if ($Script:vROConnection.token)
{
$Headers.Add("Authorization", "Bearer $($Script:vROConnection.Token)")
}
else {
$Headers.Add("Authorization", "Basic $($Script:vROConnection.EncodedPassword)")
}

# --- Run vRO REST Request
Write-Verbose -Message "Receiving response. This may take some time depending on the size of the plugin.."
$Request = Invoke-vRORestMethod -Uri $URI -Method Get -Headers $Headers -WebRequest -Verbose:$VerbosePreference
Expand Down
11 changes: 9 additions & 2 deletions src/Functions/Public/plugin-service/Import-vROPlugin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,20 @@

# --- Set custom headers for the request
$Headers = @{

"Authorization" = "Basic $($Script:vROConnection.EncodedPassword)";
"Accept" = "Application/json"
"Accept-Encoding" = "gzip,deflate,sdch";
"Content-Type" = "multipart/form-data; boundary=$($Boundary)"
}

# --- Add the Authorization header
if ($Script:vROConnection.token)
{
$Headers.Add("Authorization", "Bearer $($Script:vROConnection.Token)")
}
else {
$Headers.Add("Authorization", "Basic $($Script:vROConnection.EncodedPassword)")
}

if ($PSCmdlet.ShouldProcess($FileInfo.FullName)){

# --- Run vRO REST Request
Expand Down
Loading