Answered by:
PowerShell code in C#

Question
-
Hi,
How can I convert this one line PowerShell code to C# code
Invoke-RestMethod -Method Post -Uri 'https://s16events.azure-automation.net/webhooks?token=sdnfgknsdkfglkshnklsdfhgoihohsndfgndfgknkkdfg'
I'm using Visual Studio to do this
Please let me know
Thanks
- Edited by R.Jos Wednesday, June 19, 2019 6:23 PM
Wednesday, June 19, 2019 6:23 PM
Answers
-
The Invoke-RestMethod cmdlet is written in C#. Search InvokeRestMethodCommand.Common.cs in https://github.com/PowerShell/
Or you can just use a REST library written for C# instead. There are a lot of them on Nuget.
Visual C++ MVP- Marked as answer by Alberto PoblacionMVP Friday, July 19, 2019 6:53 PM
Wednesday, June 19, 2019 8:04 PM -
Hi R.Jos,
Thank you for posting here.
Based on your description, you want to convert PowerShell code to c# code.
I could not do it directly. However, you could try to run the powershell from C#. The following link is a good example, you could have a look.
https://blogs.msdn.microsoft.com/kebab/2014/04/28/executing-powershell-scripts-from-c/
Best Regards,
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- Proposed as answer by Jack J JunMicrosoft contingent staff Tuesday, June 25, 2019 8:53 AM
- Marked as answer by Alberto PoblacionMVP Friday, July 19, 2019 6:53 PM
Thursday, June 20, 2019 2:50 AM
All replies
-
The Invoke-RestMethod cmdlet is written in C#. Search InvokeRestMethodCommand.Common.cs in https://github.com/PowerShell/
Or you can just use a REST library written for C# instead. There are a lot of them on Nuget.
Visual C++ MVP- Marked as answer by Alberto PoblacionMVP Friday, July 19, 2019 6:53 PM
Wednesday, June 19, 2019 8:04 PM -
Hi R.Jos,
Thank you for posting here.
Based on your description, you want to convert PowerShell code to c# code.
I could not do it directly. However, you could try to run the powershell from C#. The following link is a good example, you could have a look.
https://blogs.msdn.microsoft.com/kebab/2014/04/28/executing-powershell-scripts-from-c/
Best Regards,
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- Proposed as answer by Jack J JunMicrosoft contingent staff Tuesday, June 25, 2019 8:53 AM
- Marked as answer by Alberto PoblacionMVP Friday, July 19, 2019 6:53 PM
Thursday, June 20, 2019 2:50 AM