@@ -156,22 +156,32 @@ function Invoke-ServiceNowRestMethod {
156156 throw $_
157157 }
158158
159- # TODO: this could use some work
160- # checking for content is good, but at times we'll get content that's not valid
161- # eg. html content when a dev instance is hibernating
162- if ( $response.Content ) {
163- $content = $response.content | ConvertFrom-Json
164- if ( $content.PSobject.Properties.Name -contains " result" ) {
165- $records = @ ($content | Select-Object - ExpandProperty result)
159+ # validate response
160+ switch ($Method ) {
161+ ' Delete' {
162+ if ( $response.StatusCode -ne 204 ) {
163+ throw (' "{0} : {1}' -f $response.StatusCode , $response | Out-String )
164+ }
166165 }
167- else {
168- $records = @ ($content )
166+ Default {
167+ # TODO: this could use some work
168+ # checking for content is good, but at times we'll get content that's not valid
169+ # eg. html content when a dev instance is hibernating
170+ if ( $response.Content ) {
171+ $content = $response.content | ConvertFrom-Json
172+ if ( $content.PSobject.Properties.Name -contains " result" ) {
173+ $records = @ ($content | Select-Object - ExpandProperty result)
174+ }
175+ else {
176+ $records = @ ($content )
177+ }
178+ }
179+ else {
180+ # invoke-webrequest didn't throw an error per se, but we didn't get content back either
181+ throw (' "{0} : {1}' -f $response.StatusCode , $response | Out-String )
182+ }
169183 }
170184 }
171- else {
172- # invoke-webrequest didn't throw an error per se, but we didn't get content back either
173- throw (' "{0} : {1}' -f $response.StatusCode , $response | Out-String )
174- }
175185
176186 $totalRecordCount = 0
177187 if ( $response.Headers .' X-Total-Count' ) {
@@ -187,7 +197,10 @@ function Invoke-ServiceNowRestMethod {
187197 # if option to get all records was provided, loop and get them all
188198 if ( $PSCmdlet.PagingParameters.IncludeTotalCount.IsPresent ) {
189199
190- Write-Warning " Getting $ ( $totalRecordCount - $PSCmdlet.PagingParameters.Skip ) records, this could take a while..."
200+ $retrieveRecordCount = $totalRecordCount - $PSCmdlet.PagingParameters.Skip
201+ if ( $retrieveRecordCount -ne 0 ) {
202+ Write-Warning " Getting $retrieveRecordCount records..."
203+ }
191204
192205 $setPoint = $params.body.sysparm_offset + $params.body.sysparm_limit
193206
0 commit comments