Quantcast
Channel: ONTAP Discussions topics
Viewing all articles
Browse latest Browse all 4945

401 unauthorized error while accessing Rest api URL-Powershell

$
0
0

Any Idea on resolving these kind of errors
Code
PS C:\Users\administrator.DEMO.000> $UserName ="admin"


$ControllerPassword =ConvertTo-SecureString “Netapp1!” -AsPlainText -Force
$ControllerCredential = New-Object System.Management.Automation.PsCredential($UserName,$ControllerPassword)

$url="
https://192.168.0.71/rest/v1/aggregates?limit=20
"
$a=Invoke-RestMethod -Uri $url -Method Get -Credential $ControllerCredential
$a
$a[0]

 

 

Output
Invoke-RestMethod : Error 401 - Unauthorized
Please go back to the homepage and try again.
At line:10 char:4
+ $a=Invoke-RestMethod -Uri $url -Method Get -Credential $ControllerCredential
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExceptio
n
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Cannot index into a null array.
At line:12 char:1
+ $a[0]
+ ~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray


PS C:\Users\administrator.DEMO.000>

 

 


Viewing all articles
Browse latest Browse all 4945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>