////// Logs a type and message for and exception (and all inner exceptions) on multiple log lines. /// Lines all contain a unique ID so they can be found if other lines get between them. /// /// Method name, or whatever you want. /// Custom message for the first log line /// Exception to log public static void LogException(string tag, string message, Exception ex) { string logItemId = Guid.NewGuid().ToString("N"); Log(tag, false, logItemId + " " + message); Log(tag, false, logItemId + " Exception: " + ex.GetType().Name + ": " + ex.Message); Exception Inner = ex.InnerException; int innerNumber = 1; while( Inner != null ) { Log(tag, false, logItemId + " Inner Exception " + innerNumber + " " + Inner.GetType().Name + ": " + Inner.Message); Inner = Inner.InnerException; innerNumber++; } }
If you are making an HTTP request to a RESTful web service, you can use the PowerShell Invoke-RestMethod cmdlet. This provides a very simple HTTP REST interface, and will also format the result into a PowerShell object. If you would like to use your own functions, you can follow the instructions below. This is a helper function to format (indent) an XML response from a web service. function Format-XML { Param ([string]$xml) $out = New-Object System.IO.StringWriter $Doc=New-Object system.xml.xmlDataDocument $doc.LoadXml($xml) $writer=New-Object system.xml.xmltextwriter($out) $writer.Formatting = [System.xml.formatting]::Indented $doc.WriteContentTo($writer) $writer.Flush() $out.flush() Write-Output $out.ToString() } Here is the function to make the http call. It dumps the response data on the terminal and also returns it as a string to the caller. If there is an error it will dump the HTTP status code and comment on the terminal and return the respon
Comments
Post a Comment