All Collections
Knowledge Base
Endpoint and SaaS Apps
Troubleshooting - Endpoint and SaaS Apps
Troubleshooting 'Invoke-RestMethod' error while using Reporting API with a PowerShell script
Troubleshooting 'Invoke-RestMethod' error while using Reporting API with a PowerShell script
Updated over a week ago

Problem description

The below PowerShell script helps to convert JSON data from Reporting API to a structured CSV file.

​$secpasswd = ConvertTo-SecureString "4-434103d843e4f6980b26043b221c0d1377f4dab0909509686f34d4ad8332b691" -AsPlainText -Force$Cred = New-Object System.Management.Automation.PSCredential ( 'kalpesh@kalpesh.com ', $secpasswd)$User = Invoke-RestMethod -Method 'Get' -uri " https://192.168.61.70/api/reports/v1/users " -Credential $Cred$User.data | select-object 'email_id','total_files''shared_folders', 'size' | Export-Csv -path C:\ShareDetails.csv -NoTypeInformation

It uses Invoke-RestMethod cmdlet which sends HTTP and HTTPS requests to Representational State Transfer (REST) web services that returns a richly structured data.

This article explains how to troubleshoot the below-mentioned error while using the aforementioned PowerShell script.

Error:

​The term 'Invoke-RestMethod' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line1 char:26+ $User = Invoke-RestMethod <<<< -Method 'Get' -uri " https://192.168.61.70/api/reports/v1/users " -Credential $Cred+ CategoryInfo : ObjectNotFound: (Invoke-RestMethod:String) [], CommandNotFoundException+ FullyQualifiedErrorId : CommandNotFoundException


InvokeRestmethodError.png

Cause:

The Invoke-RestMethod cmdlet was introduced in Windows PowerShell 3.0. The above error occurs if the PowerShell version installed on the machine is lower than 3.0.

Reference:

Resolution

Upgrade the PowerShell version to v3.0 or higher.

Did this answer your question?