<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: PI API 3.0 with Powershell Invoke-RestMethod in Controllers</title>
    <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505900#M1299</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I saw the same error when after I tried an alternate approach to getting PowerShell to accept the self-signed cert.&amp;nbsp; What I tried was&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;But every Invoke-RestMethod I tried after that failed with the same error message you're seeing, about an unexpected error occuring during a send.&amp;nbsp; When I ran into it, the easiest way I found to clear that error was to start a new PowerShell session.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After implementing the certificate policy instead, in a new window, things started working.&amp;nbsp; Hope that helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT:&amp;nbsp; From what I understand the error message is a known bug.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, just in case it proves relevant, here's the $PSVersionTable of my PowerShell.&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Name&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Value&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;PSVersion&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4.0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;WSManStackVersion&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3.0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;SerializationVersion&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1.1.0.1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;CLRVersion&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4.0.30319.34209&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;BuildVersion&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;6.3.9600.16406&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;PSCompatibleVersions&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;{1.0, 2.0, 3.0, 4.0}&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;PSRemotingProtocolVersion&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2.2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Aug 2016 15:36:33 GMT</pubDate>
    <dc:creator>Spencer Zier</dc:creator>
    <dc:date>2016-08-16T15:36:33Z</dc:date>
    <item>
      <title>PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505894#M1293</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to get the powershell Invoke-RestMethod to interact with the Prime Infrastructure API, but I'm not having much luck. Basically I want to retrieve a list of devices from the PI API, but I'm not sure what to put in the body for the Invoke-RestMethod command. Does anyone have any experience working with PI API and Powershell?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;James&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Aug 2016 20:03:57 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505894#M1293</guid>
      <dc:creator>rogerjam</dc:creator>
      <dc:date>2016-08-11T20:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505895#M1294</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Same here! Were you able to connect to the server? I can't ! Did you have a chance to read the tutorial? There's some detailed info but it's to connect that's my problem. I haven't tried other REST applications though.&lt;/P&gt;&lt;P&gt;Serge&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2016 15:09:20 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505895#M1294</guid>
      <dc:creator>serge.charbonneau</dc:creator>
      <dc:date>2016-08-15T15:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505896#M1295</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey, I'm not a PowerShell expert by any measure, but I did manage to get it working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, if you have a self-signed certificate for Prime Infrastructure, your requests will likely fail with the error message&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;&lt;/CODE&gt;So you'll need to get around this by setting up a new certificate policy to trust all certs.&amp;nbsp; To do that, I found &lt;A href="http://stackoverflow.com/a/15841856"&gt;an example on Stack Overflow&lt;/A&gt;, and it worked when I tested it.&amp;nbsp; Note that this certificate policy will apply to the entire PowerShell session, so &lt;STRONG&gt;use this workaround at your risk&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next, you'll need to prepare the authentication info.&amp;nbsp; You can either create a variable with your base64 encoded username:password string, or have PowerShell do the encoding for you with the following code&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;$basicAuth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("username:password")))&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, you're ready to make the actual call.&amp;nbsp; The certificate policy (if you decided to use it) is session global, so the only thing you need to have when you make the invoke is the base64 authentication string and the URL.&amp;nbsp; Here's an example&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;&lt;SPAN&gt;$response = Invoke-RestMethod "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://my_server/webacs/api/v1/data/Devices" rel="nofollow" target="_blank"&gt;https://my_server/webacs/api/v1/data/Devices&lt;/A&gt;&lt;SPAN&gt;" -headers @{Authorization=("Basic {0}" -f $basicAuth)}&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2016 16:33:26 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505896#M1295</guid>
      <dc:creator>Spencer Zier</dc:creator>
      <dc:date>2016-08-15T16:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505897#M1296</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well thanks for that important nudge &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I think that's what you might be looking for:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt;$response.queryResponse.entity.DevicesDTO | select devicename, devicetype, ipaddress, location&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt;Now for some reason, I'm getting a 401 error :-(. I think prime might be busy !&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;UPDATE:&lt;/P&gt;&lt;P&gt;Figured out that the -DisableKeepAlive is a must with the invoke-restmethod cmdlet since Prime only allows 5 concurrent connections so in trying various steps I basically locked myself out.&lt;/P&gt;&lt;P&gt;Another trick to get one final variable to hold all the device info which I ended up with is to use this line:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;$DeviceInfo = $((Invoke-RestMethod "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://myserver/webacs/api/v1/data/Devices?.full=true" rel="nofollow" target="_blank"&gt;https://myserver/webacs/api/v1/data/Devices?.full=true&lt;/A&gt;&lt;SPAN&gt;" -DisableKeepAlive -headers @{Authorization=("Basic {0}" -f $basicAuth)}) | select @{n="DeviceInfo";e={$_.queryResponse.entity.DevicesDTO}}).deviceinfo&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Then you can $DeviceInfo | select whatever.. or $DeviceInfo | out-gridview to see everything in powershell's grid from which you can copy/paste or filter columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;&lt;P&gt;Serge&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2016 18:25:36 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505897#M1296</guid>
      <dc:creator>serge.charbonneau</dc:creator>
      <dc:date>2016-08-15T18:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505898#M1297</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Spencer,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the reply! I tried that method and I'm getting the error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;I've tried multiple callback functions that I've found across the web including the Stack Exchange link you mentioned that trusts all certs. None of them have worked.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Here's what my code looks like minus all of the sensitive bits:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;function Ignore-SSLCertificates&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $Provider = New-Object Microsoft.CSharp.CSharpCodeProvider&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $Compiler = $Provider.CreateCompiler()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $Params = New-Object System.CodeDom.Compiler.CompilerParameters&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $Params.GenerateExecutable = $false&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $Params.GenerateInMemory = $true&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $Params.IncludeDebugInformation = $false&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $Params.ReferencedAssemblies.Add("System.DLL") &amp;gt; $null&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $TASource=@'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; namespace Local.ToolkitExtensions.Net.CertificatePolicy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class TrustAll : System.Net.ICertificatePolicy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public bool CheckValidationResult(System.Net.ServicePoint sp,System.Security.Cryptography.X509Certificates.X509Certificate cert, System.Net.WebRequest req, int problem)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return true;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;'@ &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $TAAssembly=$TAResults.CompiledAssembly&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## We create an instance of TrustAll and attach it to the ServicePointManager&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $TrustAll = $TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [System.Net.ServicePointManager]::CertificatePolicy = $TrustAll&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;$basicAuth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("username:password")))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;SPAN&gt;$url = '&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://hostname/webacs/api/v1/data/Devices" rel="nofollow" target="_blank"&gt;https://hostname/webacs/api/v1/data/Devices&lt;/A&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;$response = Invoke-RestMethod $url -headers @{Authorization=("Basic {0}" -f $basicAuth)}&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2016 13:01:33 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505898#M1297</guid>
      <dc:creator>rogerjam</dc:creator>
      <dc:date>2016-08-16T13:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505899#M1298</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;James I had the same issue at the beginning and used the other cert method which worked for me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="pln"&gt;add&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;-&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;type &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;@&lt;/SPAN&gt;&lt;SPAN class="str"&gt;" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;@&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;[&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;System&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;Net&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;ServicePointManager&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;]::&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;CertificatePolicy&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="typ"&gt;New&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;-&lt;/SPAN&gt;&lt;SPAN class="typ"&gt;Object&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="typ"&gt;TrustAllCertsPolicy&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="pln"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="pln"&gt;Followed by the $basicAuth..., $url..., $response (or even beter my $deviceinfo=... which I've included above.)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="pln"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="pln"&gt;Serge&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2016 14:15:40 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505899#M1298</guid>
      <dc:creator>serge.charbonneau</dc:creator>
      <dc:date>2016-08-16T14:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505900#M1299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I saw the same error when after I tried an alternate approach to getting PowerShell to accept the self-signed cert.&amp;nbsp; What I tried was&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;But every Invoke-RestMethod I tried after that failed with the same error message you're seeing, about an unexpected error occuring during a send.&amp;nbsp; When I ran into it, the easiest way I found to clear that error was to start a new PowerShell session.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After implementing the certificate policy instead, in a new window, things started working.&amp;nbsp; Hope that helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT:&amp;nbsp; From what I understand the error message is a known bug.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, just in case it proves relevant, here's the $PSVersionTable of my PowerShell.&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Name&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Value&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;PSVersion&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4.0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;WSManStackVersion&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3.0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;SerializationVersion&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1.1.0.1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;CLRVersion&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4.0.30319.34209&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;BuildVersion&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;6.3.9600.16406&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;PSCompatibleVersions&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;{1.0, 2.0, 3.0, 4.0}&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;PSRemotingProtocolVersion&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2.2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2016 15:36:33 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505900#M1299</guid>
      <dc:creator>Spencer Zier</dc:creator>
      <dc:date>2016-08-16T15:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505901#M1300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, so it looks like I'm all caught up with you guys but now I'm getting a 401 error like Serge was getting. I tried the DisableKeepAlive but still no luck. I know the credentials work for sure. Is there anything else I should try to get this to go through? I'll try restarting my powershell setting again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2016 17:39:09 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505901#M1300</guid>
      <dc:creator>rogerjam</dc:creator>
      <dc:date>2016-08-16T17:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505902#M1301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It could be that there already are 5 concurrent sessions for your user.&amp;nbsp; If possible, you could try restarting the Prime Infrastructure appliance.&amp;nbsp; Or you could try creating a new user.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2016 17:46:50 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505902#M1301</guid>
      <dc:creator>Spencer Zier</dc:creator>
      <dc:date>2016-08-16T17:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505903#M1302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I needed to wait a while before retrying again. Prime most probably has a timing threshold (maybe 15min.) before allowing connection again.&lt;/P&gt;&lt;P&gt;Serge&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2016 17:52:15 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505903#M1302</guid>
      <dc:creator>serge.charbonneau</dc:creator>
      <dc:date>2016-08-16T17:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505904#M1303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'll try again later and update this thread. Thanks for the assistance gentlemen.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;James&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2016 18:05:27 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505904#M1303</guid>
      <dc:creator>rogerjam</dc:creator>
      <dc:date>2016-08-16T18:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505905#M1304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm sort of at a loss as of now. I'm still getting a 401 Unauthorized error when trying to access through Powershell, but I can access it just fine thru curl using the same credentials.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;James&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Aug 2016 21:26:24 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505905#M1304</guid>
      <dc:creator>rogerjam</dc:creator>
      <dc:date>2016-08-18T21:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505906#M1305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, looks like I fixed it. I manually encoded the username:password string to base64 using a website converter and changed the quotes on my URL string to a double quote instead of single quote and it worked after that. Now, I'm curious how do I get a complete list of devices? It is only showing me 100 devices at a time and it looks like there are over 2300.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;James&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Aug 2016 21:49:12 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505906#M1305</guid>
      <dc:creator>rogerjam</dc:creator>
      <dc:date>2016-08-18T21:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: PI API 3.0 with Powershell Invoke-RestMethod</title>
      <link>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505907#M1306</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is called "pagination".&amp;nbsp; You can "page" through the results using multiple calls&lt;/P&gt;&lt;P&gt;.maxResults - is the number of devices to return.&lt;/P&gt;&lt;P&gt;.firstResult - is the place to start from.&amp;nbsp; (Initially 1).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#NOTE: there is a "." for each of these keys.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this would get the next 50 results after the first 100.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;requestUrl="&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://my_server/webacs/api/v1/data/Devices?.full=true&amp;amp;.maxResults=50&amp;amp;.firstResult=100" rel="nofollow" target="_blank"&gt;https://my_server/webacs/api/v1/data/Devices?.full=true&amp;amp;.maxResults=50&amp;amp;.firstResult=100&lt;/A&gt;&lt;SPAN&gt;" &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Aug 2016 22:01:10 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/pi-api-3-0-with-powershell-invoke-restmethod/m-p/3505907#M1306</guid>
      <dc:creator>aradford</dc:creator>
      <dc:date>2016-08-18T22:01:10Z</dc:date>
    </item>
  </channel>
</rss>

