$rs.write($contentDisp,0,$contentDisp.Length);

[byte[]]$contentType = [System.Text.Encoding]::UTF8.GetBytes($conType + "`r`n`r`n"); $rs.write($contentType,0,$contentType.Length);

$fs.CopyTo($rs,$bufferSize) $fs.close()

[byte[]]$endBoundaryBytes = [System.Text.Encoding]::UTF8.GetBytes("`n`r`n--" + $boundary + "--`r`n"); $rs.write($endBoundaryBytes,0,$endBoundaryBytes.Length);

$rs.close()

}

catch [System.Exception]

{

Write-Host "Not able to send backup" Write-Host $error[0].Exception

}

try

{

[net.httpsWebResponse]$response = $uploadRequest.getResponse() $responseStream = $response.getResponseStream() $responseStream.ReadTimeout = $uploadTimeout

$streamReader = New-Object IO.StreamReader ($responseStream) $rawUploadResponse = $streamReader.readtoend() $response.close()

if ($rawUploadResponse -eq $null)

{

return

}

$uploadResponse = $rawUploadResponse convertFrom-Json

if ($uploadResponse.status -eq "SUCCEEDED")

{

Write-Host "Upload complete." return $uploadResponse

}

else

{

Write-Host $rawUploadResponse Write-Host $uploadResponse return

}

}

catch [Net.WebException]

{

Write-Host $error[0]

$errorResponse = $error[0].Exception.InnerException.Response.getResponseStream() $sr = New-Object IO.StreamReader ($errorResponse)

$frawErrorStream = $sr.readtoend()

$error[0].Exception.InnerException.Response.close() $errorObject = $rawErrorStream convertFrom-Json

Write-Host $errorObject.errorcode $errorObject.message $errorObject.resolution return

}

}

##### Initiate the restore process #####

function start-restore ([string]$authinfo,[string]$hostname,[object]$uploadResponse)

{

<#

.DESCRIPTION

Sends a POST request to the restore resource to initiate a restore.

.PARAMETER authinfo

The authorized sessionID obtained from login.

.PARAMETER hostname

The appliance to connect to.

.PARAMETER uploadResponse

The response body from the upload request. Contains the backup URI needed for restore call.

.INPUTS

None, does not accept piping

.OUTPUTS

Outputs the response body from the POST restore call.

.EXAMPLE

$restoreResponse = start-restore $sessionID $hostname $uploadResponse

#>

#append the appropriate URI to the IP address of the Appliance $backupUri = $uploadResponse.uri

$restoreUri = "/rest/restores"

$fullRestoreUri = $hostname + $restoreURI

$body = @{ type = "RESTORE"; uriOfBackupToRestore = $backupUri } convertTo-json

#create a new webrequest and add the proper headers

try

{

288 Backup and restore script examples