RegistryKey adaptersRegKey = Registry.LocalMachine; adaptersRegKey = adaptersRegKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Adapters"); String[] adapterGuids = adaptersRegKey.GetSubKeyNames(); foreach (String giud in adapterGuids) { RegistryKey interfaceRegKey = Registry.LocalMachine; interfaceRegKey = interfaceRegKey.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" + giud); try { Console.WriteLine("Checking: " + giud); Object ipObject = interfaceRegKey.GetValue("IPAddress"); Array ipArray = (Array)ipObject; foreach (string ip in ipArray) { Console.WriteLine("Found IP: " + ip); } interfaceRegKey.Close(); } catch (NullReferenceException) { } } adaptersRegKey.Close();
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