HP Insight Control Server Provisioning 7.3 Update 1 Administrator Guide

#########################################################################################
# exit if an error occurs during login POST
if( !$loginresponse) { Write-Host "*** ERROR *** Login Failed"; exit; }
#########################################################################################
# extract token from response
$bodytokens = $loginresponse.split("`"")
$token = $bodytokens[3]
#########################################################################################
# make all subsequent requests with the auth token
$webclient.Headers.add('auth', "$token")
Below is an example Powershell v3 script that will get the full details of all the jobs on the appliance
or for a single job identified by job id:
#########################################################################################
# functions for the script
function showJobDetails($thisjoburi)
{
# get the details for a single job
$jobdetails = $webclient.DownloadString("$thisjoburi") | ConvertFrom-Json
Write-Host "`n`n$thisjoburi parsed JSON:`n"
$jobdetails
#Write-Host "`n`n$thisjoburi RESULT:`n"
#$jobdetails.jobResult
}
#########################################################################################
# setup default values for script
$applianceip = "10.1.1.7"
$username = "administrator"
$password = "hpvse123"
$joblistonly = $false
#########################################################################################
# process command line arguments
foreach($arg in $args)
{
switch -regex ($arg)
{
"-[uU](.+)" { $username = $matches[1]; Write-Host "setting user to: $username"; }
"-[pP](.+)" { $password = $matches[1]; Write-Host "setting password to: $password"; }
"-[aA](.+)" { $applianceip = $matches[1]; Write-Host "setting applianceip to: $applianceip"; }
"-[lL](.+)" { $joblistonly = $true; Write-Host "only show job list, not details
(applies to 7.2.1 and earlier)"; }
"-[jJ](.+)" { $onejob = $matches[1]; Write-Host "getting details only for job $onejob"; }
default { Write-Host "unknown argument: $arg"; }
}
}
#########################################################################################
# set up script variables/values
$loginurl = "https://$applianceip/rest/login-sessions"
$joblisturl = "https://$applianceip/rest/os-deployment-jobs"
$loginbody = "{`"userName`":`"$username`",`"password`":`"$password`"}"
#########################################################################################
# accept all certificates as part of handshake - used so that self-signed certs
# from IC server provisioning are accepted
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$webclient = New-Object System.Net.WebClient
#########################################################################################
# set up the request headers
$webclient.Headers.add('content-type', 'application/json')
$webclient.Headers.add('accept', 'application/json')
#########################################################################################
# attempt to login
$loginresponse = $webclient.uploadString($loginurl, $loginbody) | ConvertFrom-Json
#########################################################################################
# exit if an error occurs during login POST
112 Advanced topics