NetApp Community Update
This site will enter Read Only mode on July 23 as we prepare to move to a new platform. You will still be able to view content, but posting and replying will be temporarily disabled.
We're excited to launch our new Community experience on July 30 and more information will follow soon.
Stay connected during the transition - Join our Discord community today.

ONTAP Discussions

401 unauthorized error while accessing Rest api URL-Powershell

ashish9711
7,919 Views

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>

 

 

3 REPLIES 3

GidonMarcus
7,907 Views

Hi, see post from earlier this month.

https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/credentials-with-powershell/td-p/156757

Gidi Marcus (Linkedin) - Storage and Microsoft technologies consultant - Hydro IT LTD - UK

ashish9711
7,876 Views

@GidonMarcus : None of the solutions listed in the link contains solution to my question. 

ashish9711
7,857 Views

Got it fixed. OCUM uses a different accept parameter in header variable compared to other gui's

Public