Anyone know how to invoke a Rest Web API from a powershell script?

Hey all,

So I am clueless with Powershell.   Not even sure how to run this powershell file after I create it.   I simply need to invoke a Web API call somehow from a script and someone told me powershell can do this.   Any example on how to do this if I give it the URL such as:

http://localhost:51828/api/Customer/Generate

Then if someone can tell me how to invoke assuming I have powershell installed on my machine.

Thanks all.
sbornstein2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alexandre SimõesManager / Technology SpecialistCommented:
I didn't know but found it interesting :)
REST calls are nothing but HTTP requests, so from PowerShell you can just use the .Net web client:
$wc = New-Object system.Net.WebClient;
$result = $wc.downloadString("http://localhost:51828/api/Customer/Generate")

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
footechCommented:
A couple other options.  If you don't know anything about PowerShell then I don't know how helpful they will be since it only gets you started.  Depending on what is returned by the request the next steps vary.

$result = Invoke-WebRequest -Uri "http://localhost:51828/api/Customer/Generate"

# or

$url = "http://localhost:51828/api/Customer/Generate"
$result = Invoke-RestMethod -URI $url -Method GET

# now look at the contents of $result

Open in new window

0
sbornstein2Author Commented:
tx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.