| 134 |
Write-Verbose "Performing token refresh" |
| 135 |
$AccessToken |
| 135 |
Update-GraphOauthAccessToken -ErrorAction Stop |
| 138 |
$ErrorMessage = "Unable to refresh Access Token '{0}': {1}" -f $AccessToken.GUID, $_.Exception.Message |
| 139 |
Write-Error $ErrorMessage |
| 142 |
if (-not $pscmdlet.ShouldProcess("$Uri")) { ... |
| 145 |
Write-Verbose "Set base parameters" |
| 146 |
$Params = @{ ... |
| 147 |
ContentType = $ContentType |
| 148 |
Uri = $Uri |
| 149 |
WebSession = $AccessToken.Session |
| 150 |
Method = $Method |
| 151 |
ErrorAction = 'Stop' |
| 153 |
if ($Body) { ... |
| 154 |
Write-Verbose "Setting Body Parameter" |
| 155 |
$Params['Body'] = $Body |
| 157 |
if ($TimeoutSec) { ... |
| 158 |
Write-Verbose "Setting TimeoutSec Parameter" |
| 159 |
$Params['TimeoutSec'] = $TimeoutSec |
| 161 |
Write-Verbose "Setting Headers Parameter" |
| 162 |
$Params['Headers'] = @{ } |
| 163 |
if ($Headers) { ... |
| 164 |
Write-Verbose "Setting user supplied headers" |
| 165 |
$Params['Headers'] = $Headers |
| 167 |
Write-Verbose "Setting Authorization header" |
| 168 |
$Params['Headers']['Authorization'] = 'Bearer {0}' -f $AccessToken.GetAccessToken() |
| 169 |
$RequestedDate = Get-Date |
| 171 |
$Result = Invoke-WebRequest @Params |
| 172 |
$ReceivedDate = Get-Date |
| 175 |
$response = $_.Exception.Response |
| 176 |
$Stream = $response.GetResponseStream() |
| 177 |
$Stream.Position = 0 |
| 178 |
$StreamReader = New-Object System.IO.StreamReader $Stream |
| 179 |
$ResponseBody = $StreamReader.ReadToEnd() |
| 180 |
$ErrorMessage = "Unable to query Uri '{0}': {1}: {2}" -f $Uri, $_.Exception.Message, $ResponseBody |
| 181 |
Set-Variable -Scope global -Name _invokeGraphRequestException -Value $_ |
| 182 |
Write-Error -message $ErrorMessage -Exception $_.Exception |
| 185 |
Write-Verbose "Truncating Authorization header" |
| 187 |
$Params['Headers']['Authorization'] = '{0}...{1}<truncated>' -f $Params.Headers.Authorization.Substring(0, 25), ... |
| 188 |
$Params.Headers.Authorization.Length - 11 |
| 191 |
Write-Verbose "No Authorization header to truncate" |
| 193 |
$Result.Headers.'Content-Type' |
| 194 |
$_ -match 'application/json' |
| 195 |
Write-Verbose "Converting result from JSON to PSObject" |
| 196 |
$ConentObject = $Result.Content ... |
| 196 |
$ConentObject = $Result.Content ... |
| 199 |
$_ -match 'application/xml' |
| 200 |
Write-Verbose "Converting result from XML to PSObject" |
| 201 |
[xml]$ConentObject = $Result.Content |
| 205 |
Write-Verbose "Unhandled Content-Type. ContentObject will be raw." |
| 206 |
$ConentObject = $Result.Content |
| 209 |
Write-Verbose "Setting LastRequestDate on Access Token" |
| 210 |
$AccessToken.LastRequestDate = $RequestedDate |
| 211 |
[pscustomobject]@{ ... |
| 212 |
PSTypeName = 'MSGraphAPI.RequestResult' |
| 213 |
Result = $Result |
| 214 |
Uri = $Uri |
| 215 |
Headers = $Params.Headers |
| 216 |
InvokeWebRequestParameters = $Params |
| 217 |
ContentType = $ContentType |
| 218 |
TimeoutSec = $TimeoutSec |
| 219 |
Body = $Body |
| 220 |
RequestedDate = $RequestedDate |
| 221 |
RecievedDate = $ReceivedDate |
| 222 |
AccessToken = $AccessToken |
| 223 |
ContentObject = $ConentObject |
Code coverage report:
Covered 0 % of 66 analyzed Commands in
Invoke-GraphRequestMissed commands:
Write-Verbose "Performing token refresh"$AccessTokenUpdate-GraphOauthAccessToken -ErrorAction Stop$ErrorMessage = "Unable to refresh Access Token '{0}': {1}" -f $AccessToken.GUID, $_.Exception.MessageWrite-Error $ErrorMessageif (-not $pscmdlet.ShouldProcess("$Uri")) { ...Write-Verbose "Set base parameters"$Params = @{ ...ContentType = $ContentTypeUri = $UriWebSession = $AccessToken.SessionMethod = $MethodErrorAction = 'Stop'if ($Body) { ...Write-Verbose "Setting Body Parameter"$Params['Body'] = $Bodyif ($TimeoutSec) { ...Write-Verbose "Setting TimeoutSec Parameter"$Params['TimeoutSec'] = $TimeoutSecWrite-Verbose "Setting Headers Parameter"$Params['Headers'] = @{ }if ($Headers) { ...Write-Verbose "Setting user supplied headers"$Params['Headers'] = $HeadersWrite-Verbose "Setting Authorization header"$Params['Headers']['Authorization'] = 'Bearer {0}' -f $AccessToken.GetAccessToken()$RequestedDate = Get-Date$Result = Invoke-WebRequest @Params$ReceivedDate = Get-Date$response = $_.Exception.Response$Stream = $response.GetResponseStream()$Stream.Position = 0$StreamReader = New-Object System.IO.StreamReader $Stream$ResponseBody = $StreamReader.ReadToEnd()$ErrorMessage = "Unable to query Uri '{0}': {1}: {2}" -f $Uri, $_.Exception.Message, $ResponseBodySet-Variable -Scope global -Name _invokeGraphRequestException -Value $_Write-Error -message $ErrorMessage -Exception $_.ExceptionWrite-Verbose "Truncating Authorization header"$Params['Headers']['Authorization'] = '{0}...{1}<truncated>' -f $Params.Headers.Authorization.Substring(0, 25), ...$Params.Headers.Authorization.Length - 11Write-Verbose "No Authorization header to truncate"$Result.Headers.'Content-Type'$_ -match 'application/json'Write-Verbose "Converting result from JSON to PSObject"$ConentObject = $Result.Content ...$ConentObject = $Result.Content ...$_ -match 'application/xml'Write-Verbose "Converting result from XML to PSObject"[xml]$ConentObject = $Result.ContentWrite-Verbose "Unhandled Content-Type. ContentObject will be raw."$ConentObject = $Result.ContentWrite-Verbose "Setting LastRequestDate on Access Token"$AccessToken.LastRequestDate = $RequestedDate[pscustomobject]@{ ...PSTypeName = 'MSGraphAPI.RequestResult'Result = $ResultUri = $UriHeaders = $Params.HeadersInvokeWebRequestParameters = $ParamsContentType = $ContentTypeTimeoutSec = $TimeoutSecBody = $BodyRequestedDate = $RequestedDateRecievedDate = $ReceivedDateAccessToken = $AccessTokenContentObject = $ConentObject