2024-07-26 21:13:08 +00:00
|
|
|
$SparkHeaders = @{
|
|
|
|
|
"Content-Type" = "application/json"
|
|
|
|
|
"Authorization" = ""
|
|
|
|
|
"Accept" = "*/*"
|
|
|
|
|
"Accept-Encoding" = "gzip, deflate, br"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$SparkTenantPrefix = "samaritanhealth-amc"
|
|
|
|
|
$SparkURL = "https://$SparkTenantPrefix.ivanticloud.com"
|
|
|
|
|
|
|
|
|
|
Function Connect-ISM {
|
|
|
|
|
try {
|
|
|
|
|
#Try a fast route to check if authorization headers are set properly
|
|
|
|
|
Invoke-RestMethod -Method Get -URI "$SparkURL/api/odata" -Headers $SparkHeaders
|
|
|
|
|
} catch {
|
|
|
|
|
$errobject = ConvertFrom-Json $_
|
|
|
|
|
#A 404 means we were authorized and didn't find anything, as intended!
|
|
|
|
|
if ($errobject.code -eq "ISM_4004") { return }
|
|
|
|
|
#Anything other than a 401 Unauthorized is unexpected, attempt to handle gracefully
|
|
|
|
|
if ($errobject.code -ne "ISM_4001") {
|
|
|
|
|
Write-Host -ForegroundColor Red "Unexpected error connecting to Spark!"
|
|
|
|
|
Write-Host -ForegroundColor Red "$errobject"
|
|
|
|
|
$SparkHeaders["Authorization"] = ""
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
#Unuathorized response, so let's update our authorization!
|
|
|
|
|
if ( $SparkHeaders["Authorization"] ) {
|
|
|
|
|
Write-Host "Spark Authorization key expired, please update key"
|
|
|
|
|
}
|
|
|
|
|
$authKey = Read-Host "Login to Spark, open browser dev tools, and paste SID cookie here, or an API key if you have one"
|
|
|
|
|
if ($authKey -match "[0-9A-F](32)") {
|
|
|
|
|
$SparkHeaders["Authorization"] = "rest_api_key=$authKey"
|
|
|
|
|
} elseif ($authKey -match "$($SparkURL.split('/')[-1])#.*#") {
|
|
|
|
|
$SparkHeaders["Authorization"] = $authKey
|
|
|
|
|
} else {
|
|
|
|
|
Write-Host -ForegroundColor Yellow "Authorization key not a recognized key format"
|
|
|
|
|
$SparkHeaders["Authorization"] = ""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Function Check-SparkEnabled {
|
|
|
|
|
return -not -not $SparkHeaders["Authorization"]
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-30 20:25:32 +00:00
|
|
|
Function Search-SparkCIs($CIName) {
|
|
|
|
|
Connect-ISM
|
|
|
|
|
$uri = "$SparkURL/api/odata/businessobject/CIs`?`$filter=Name+eq+%27$CIName%27&`$top=100&`$skip=0"
|
|
|
|
|
try{
|
|
|
|
|
$Query = Invoke-RestMethod -Method GET -uri $uri -headers $SparkHeaders
|
|
|
|
|
} catch {
|
|
|
|
|
$ExceptionErrors += $_.Exception.Message
|
|
|
|
|
}
|
|
|
|
|
return $Query.Value
|
|
|
|
|
}
|