if ($authValue -ne "0")

{

$request.Headers.Item("auth") = $authValue

}

$request.Headers.Add("X-API-Version: $global:scriptApiVersion") if ($body -ne $null)

{

#write-host $body

$requestBodyStream = New-Object IO.StreamWriter $request.getRequestStream() $requestBodyStream.WriteLine($body)

$requestBodyStream.flush() $requestBodyStream.close()

}

#attempt to connect to the Appliance and get a response [net.httpsWebResponse]$response = $request.getResponse()

#response stored in a stream

$responseStream = $response.getResponseStream()

$sr = New-Object IO.StreamReader ($responseStream)

#the stream, which contains a json object is read into the storage variable $rawResponseContent = $sr.readtoend()

$response.close()

return $rawResponseContent

}

catch [Net.WebException]

{

try

{

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

$rawErrorStream = $sr.readtoend()

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

Write-Host $errorObject.message $errorObject.recommendedActions

}

catch [System.Exception]

{

Write-Host $error[1].Exception.Message

}

throw return

}

}

##### Begin main #####

#this checks to see if the user wants to just check a status of an existing restore if ($args.count -eq 2)

{

foreach ($item in $args)

{

if ($item -eq "-status")

{

[void]$foreach.movenext()

$hostname = $foreach.current

#Correct some common errors in hostname $hostname = $hostname.Trim().ToLower() if (!$hostname.StartsWith("https://"))

{

if ($hostname.StartsWith("http://"))

{

$hostname = $hostname.Replace("http","https") } else {

$hostname = "https://" + $hostname

}

}

}

else

{

Write-Host "Invalid arguments." return

}

}

$reacquiredUri = recover-restoreID -hostname $hostname if ($reacquiredUri -eq $null)

{

Write-Host "Error occurred when fetching active restore ID. No restore found." return

}

restore-status -recoveredUri $reacquiredUri -hostname $hostname

return

}

elseif ($args.count -eq 0)

{

C.2 Sample restore script 291