HP OneView 1.05 User Guide

# create the request body as a hash table, then convert it to json format
$body = @{ userName = $username; password = $password } | convertTo-json
# use setup-request to issue the REST request to login and get the response
try
{
$loginResponse = setup-request -Uri $fullLoginUri -method "POST" -accept "application/json" -contentType
"application/json" -Body $body
if ($loginResponse -ne $null)
{
$loginResponse | convertFrom-Json
}
}
catch [System.Exception]
{
if ($global:interactiveMode -eq 1)
{
Write-Host $error[0].Exception.Message
}
else
{
Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message $error[0].Exception.Message
}
}
}
##### Executing backup ######
function backup-Appliance ([string]$authValue,[string]$hostname)
{
<#
.DESCRIPTION
Gives the appliance the command to start creating a backup
.PARAMETER authValue
The authorized sessionID given by login-appliance
.PARAMETER hostname
The location of the appliance to connect to (in https://{ipaddress} format)
.INPUTS
None, does not accept piping
.OUTPUTS
The task Resource returned by the appliance, converted to a hashtable object
.EXAMPLE
$taskResource = backup-Appliance $sessionID $hostname
#>
# append the REST Uri for backup to the IP address of the Appliance
$bkupUri = "/rest/backups/"
$fullBackupUri = $hostname + $bkupUri
# create a new webrequest and add the proper headers (new header, auth, is needed for authorization
# in all functions from this point on)
try
{
if ($global:scriptApiVersion -lt $taskResourceV2ApiVersion)
{
$taskResourceJson = setup-request -Uri $fullBackupUri -method "POST" -accept "application/json" -contentType
"application/json" -authValue $authValue
}
else
{
$taskUri = setup-request -Uri $fullBackupUri -method "POST" -accept "application/json" -contentType
"application/json" -authValue $authValue -returnLocation $true
if ($taskUri -ne $null)
{
$taskResourceJson = setup-request -Uri $taskUri -method "GET" -accept "application/json" -contentType
"application/json" -authValue $authValue
}
}
if ($taskResourceJson -ne $null)
{
return $taskResourceJson | ConvertFrom-Json
}
}
catch [System.Exception]
{
if ($global:interactiveMode -eq 1)
{
Write-Host $error[0].Exception.Message
}
else
{
Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message $error[0].Exception.Message
}
}
}
##### Polling to see if backup is finished ######
C.1 Sample backup script 295