{"id":308046,"date":"2020-08-05T15:01:31","date_gmt":"2020-08-05T15:01:31","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=308046"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=308046","title":{"rendered":"\u041f\u0440\u0438\u0442\u0432\u043e\u0440\u044f\u0435\u043c\u0441\u044f \u0447\u0442\u043e \u043f\u0438\u0448\u0435\u043c \u043d\u0430 C#, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 Powershell"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/513900\/\"><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/513900\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/js\/yc\/na\/jsycnamvumej2vknuwh2jqsibe4.png\"><\/div>\n<p><\/a><br \/>  Powershell \u2014 \u0443\u0434\u043e\u0431\u043d\u0430\u044f API \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u043d\u0430 .net. Powershell \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442\u044b, \u043d\u0435 \u0443\u043f\u0438\u0440\u0430\u044f\u0441\u044c \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u044f \u0441\u0445\u043e\u0436\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u041a\u0414\u0412\u041f, \u0430\u0432\u0442\u043e\u0440 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442 \u043f\u043e\u0437\u0436\u0435 \u043f\u043e \u0442\u0435\u043a\u0441\u0442\u0443. \u0421\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u043c \u0441\u0440\u043e\u0447\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0442\u0432\u043e\u0440\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u043d\u0430 C#.<\/p>\n<p>  TL;DR: Postman \u043d\u0435 \u043d\u0443\u0436\u0435\u043d, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c Powershell. \u041d\u043e \u0441\u043f\u0435\u0440\u0432\u0430 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0439\u0442\u0438 \u0438\u0437\u0434\u0430\u043b\u0435\u043a\u0430.<a name=\"habracut\"><\/a><\/p>\n<h2><font color=\"#3AC1EF\">\u0414\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043b\u0430\u0441\u0441<\/font><\/h2>\n<p>  \u0410\u0432\u0442\u043e\u0440 \u0441\u043b\u044b\u0448\u0430\u043b, \u0447\u0442\u043e \u043a\u0440\u0443\u0442\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u0434\u0435\u043b\u0430\u044e\u0442 \u0432\u0441\u0435 \u0447\u0435\u0440\u0435\u0437 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u044b. <br \/>  \u0422\u0430\u043a \u043a\u0430\u043a PowerShell \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0430\u0432\u0442\u043e\u0440 \u043f\u043e\u043a\u0430\u0436\u0435\u0442, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u043b\u043e\u0436\u0438\u0442\u044c 1 + 1 \u043f\u0440\u0438\u0442\u0432\u043e\u0440\u0438\u0432\u0448\u0438\u0441\u044c, \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u0435\u043c.<\/p>\n<pre><code class=\"powershell\">class ClassName {       [string] Sum ($A, $B) {                 $Result = $A + $B         return $Result     } } <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 ClassName \u0438 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434 Sum. \u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0440\u043e\u0432\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code class=\"powershell\">$NewClass = [ClassName]::new() $NewClass.Sum(1, 1)<\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434, \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<h2><font color=\"#3AC1EF\">\u0415\u0441\u0442\u044c \u043b\u0438 Void \u0432 Powershell<\/font><\/h2>\n<p>  \u041f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u044d\u0442\u043e\u0442 \u0436\u0435 \u0432\u043e\u043f\u0440\u043e\u0441 \u0432\u0441\u0442\u0430\u0432\u0430\u043b \u0443 \u0430\u0432\u0442\u043e\u0440\u0430. \u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 Void? <\/p>\n<p>  \u0413\u043e\u0432\u043e\u0440\u044f\u0442, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"powershell\">Get-Date | Out-Null<\/code><\/pre>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e, | Out-Null \u0442\u0430\u043a \u0436\u0435 \u0433\u043b\u0443\u0448\u0438\u0442 \u0432\u0435\u0441\u044c Verbose, ErrorAction \u0438 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 Invoke-Command. <\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441 [Void] \u2013 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0432\u044b\u0445\u043e\u0434\u0430 \u043d\u0435\u0442. <\/p>\n<pre><code class=\"powershell\">class ClassName {       #\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430     [void] Start () {         #\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u044f\u043c\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u0442\u043e\u0433\u043e \u0436\u0435 \u043a\u043b\u0430\u0441\u0441\u0430.         $q = [ClassName]::new()         $q.GetDate()     }       #\u0421\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u043c\u0435\u0442\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430     [void] GetDate () {         #\u0410 \u0432\u043e\u0442 \u0442\u0443\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434 \u0438\u0437 .Net \t  #\u041f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u043c         $Result = [DateTime]::UtcNow.ToString()         Write-Host $Result     } } <\/code><\/pre>\n<p>  \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0438\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u0442\u043e\u0433\u043e \u0436\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 PowerShell \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043b\u0435\u043f\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0432\u043e\u0442 \u0432\u044b\u0437\u043e\u0432\u044b.<br \/>  \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0432 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u044f\u0437\u044b\u043a\u0430 \u0438 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0446\u0435\u043b\u043e\u043c \u043d\u0435 \u0441\u0442\u043e\u0438\u0442.<\/p>\n<p>  \u0412\u043e\u0442 \u0442\u0430\u043a \u043c\u044b \u0434\u043e\u0431\u0438\u043b\u0438\u0441\u044c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0435 \u0437\u0430\u0433\u043b\u0443\u0448\u0438\u043b\u0438 Verbose, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 Void.<\/p>\n<h2><font color=\"#3AC1EF\">\u0421\u043f\u0438\u0441\u043e\u043a \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430<\/font><\/h2>\n<p>  \u0421\u043a\u0430\u0436\u0435\u043c, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0434\u0430\u0436\u0435 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435. \u0412\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043a\u043b\u0430\u0441\u0441, \u043d\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u0435\u0433\u043e \u043f\u043b\u043e\u0445\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b. <\/p>\n<p>  \u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"powershell\">#\u0414\u0435\u043b\u0430\u0435\u043c \u043b\u044e\u0431\u043e\u0432\u044c, \u0430 \u043d\u0435 \u043a\u043b\u0430\u0441\u0441 $Love = [ClassName]::new()   #\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0447\u043b\u0435\u043d\u044b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0435\u0433\u043e \u043d\u0430\u0441 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u043c\u0430\u0441\u0441\u0438\u0432. foreach ($i in $Love | Get-Member -MemberType Method | Select-Object name) {     [array]$array += $i.Name }   #\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0447\u043b\u0435\u043d\u044b \u043a\u043b\u0430\u0441\u0441\u0430, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e. $Array | ForEach-Object {     $Love.$_() } <\/code><\/pre>\n<p>  <\/p>\n<h2><font color=\"#3AC1EF\">\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c (\u043e\u043f\u0440\u0430\u0432\u0434\u044b\u0432\u0430\u0435\u043c \u041a\u0414\u041f\u0412)<\/font><\/h2>\n<p>  \u041a\u043b\u0430\u0441\u0441\u0430\u043c\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c POST \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0432\u0435\u0431 \u0441\u0430\u0439\u0442 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON.<\/p>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043d\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440.<\/p>\n<pre><code class=\"powershell\">#\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u0435\u043b\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 class DataModel {     $Data     $TimeStamp }   #\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 $i = [DataModel]::new()   #\u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 $i.Data = &quot;My Message in string&quot; $i.TimeStamp = Get-Date <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"powershell\">PS C:\\&gt; $i   Data                 TimeStamp ----                 --------- My Message in string 30.07.2020 5:51:56<\/code><\/pre>\n<p>  \u041f\u043e\u0442\u043e\u043c \u044d\u0442\u043e\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 XML \u0438\u043b\u0438 JSON \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 SQL \u0437\u0430\u043f\u0440\u043e\u0441. \u041e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f \u043d\u0430 JSON:<\/p>\n<pre><code class=\"powershell\">#\u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 JSON $Request = $i | ConvertTo-Json<\/code><\/pre>\n<p>  \u0422\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 JSON \u043f\u043e\u0441\u043b\u0435 \u0435\u0433\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"powershell\">PS C:\\&gt; $Request {   &quot;Data&quot;: &quot;My Message in string&quot;,   &quot;TimeStamp&quot;: &quot;2020-07-30T05:51:56.6588729+03:00&quot; } <\/code><\/pre>\n<p>  \u0418 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c:<\/p>\n<pre><code class=\"powershell\">#\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c JSON Invoke-WebRequest localhost -Body $Request -Method Post -UseBasicParsing<\/code><\/pre>\n<p>  \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 JSON \u0444\u0430\u0439\u043b 24\/7, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a \u0444\u0430\u0439\u043b \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0443\u0436\u0435 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u044d\u0442\u043e\u0442 \u0436\u0435 \u0441\u0430\u043c\u044b\u0439 $Request.<\/p>\n<pre><code class=\"powershell\">#\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u043d\u0435\u0435 \u0432 JSON \u0432 \u0444\u0430\u0439\u043b $Request | Set-Content C:\\Users\\User\\Desktop\\YourRequest.json   #\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u0432 \u0444\u0430\u0439\u043b JSON Invoke-WebRequest localhost -Body (Get-Content C:\\Users\\User\\Desktop\\YourRequest.json) -Method Post -UseBasicParsing<\/code><\/pre>\n<p>  <\/p>\n<h2><font color=\"#3AC1EF\">\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c (\u043e\u043f\u0440\u0430\u0432\u0434\u044b\u0432\u0430\u0435\u043c \u041a\u0414\u041f\u0412 2)<\/font><\/h2>\n<p>  \u0410\u0432\u0442\u043e\u0440 \u0442\u0435\u0440\u043f\u0435\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 Postman, \u0437\u0430\u0447\u0435\u043c \u043a\u043e\u043c\u0443-\u043b\u0438\u0431\u043e \u043d\u0443\u0436\u0435\u043d Postman, \u043a\u043e\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0440\u0443\u043a\u0438 \u0438 PowerShell? (\u0410\u0432\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u0432\u0437\u044f\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0438 \u0435\u0433\u043e \u043d\u0435\u043b\u044e\u0431\u043e\u0432\u044c \u043d\u0438\u0447\u0435\u043c \u043d\u0435 \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430.)<br \/>  \u0414\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u044d\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e System.Net.HttpListener, \u0442\u043e \u0435\u0441\u0442\u044c \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0432\u0435\u0431 \u0441\u0435\u0440\u0432\u0435\u0440 \u0438\u0437 \u0441\u043a\u0440\u0438\u043f\u0442\u0430. <\/p>\n<pre><code class=\"powershell\">#\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 $http = [System.Net.HttpListener]::new()   #\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c HTTP \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u044b. \u0418\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e $http.Prefixes.Add(&quot;http:\/localhost\/&quot;) $http.Prefixes.Add(&quot;http:\/\/127.0.0.1\/&quot;)   #\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0445\u0442\u0442\u043f \u043b\u0438\u0441\u0442\u0435\u043d\u0435\u0440 $http.Start()     $http.Close() <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u043f\u0443\u0441\u043a \u043a\u043b\u0430\u0441\u0441\u0430. <\/p>\n<p>  \u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0438 \u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0441\u044f, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u043e\u0442 \u043d\u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434. \u0412\u044b\u0432\u043e\u0434 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u0430\u043a System.Net.HttpListener.GetContext. \u0412 \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u0438 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e POST \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<pre><code class=\"powershell\">while ($http.IsListening) {       #GetContext \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u044b\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 HttpListener     $context = $http.GetContext()       #\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0442\u0438\u043f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Request.HttpMethod      if ($context.Request.HttpMethod -eq 'POST') {           #\u0427\u0438\u0442\u0430\u0435\u043c \u0441\u044b\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 GetContext         #\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0432\u043e\u0439 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440         [System.IO.StreamReader]::new($context.Request.InputStream).ReadToEnd() | ForEach-Object {                          #\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e System.Web.HttpUtility \u0434\u0435\u043b\u0430\u0435\u043c urlDecore, \u0438\u043d\u0430\u0447\u0435 \u043a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0443\u043d\u044b             $DecodedContent = [System.Web.HttpUtility]::UrlDecode($_)               #\u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u0438\u043b\u0435\u0442\u0435\u0432\u0448\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u0444\u043e\u0440\u043c\u0430\u0442             $ConvertedForm = $DecodedContent | ConvertFrom-Json -ErrorAction SilentlyContinue               #C\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u043e\u0439             $ConvertedForm | Format-Table                     }     } }  <\/code><\/pre>\n<p>  <\/p>\n<h2><font color=\"#3AC1EF\">\u0413\u043e\u0442\u043e\u0432\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442<\/font><\/h2>\n<p>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b:<\/p>\n<pre><code class=\"powershell\">#\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 $http = [System.Net.HttpListener]::new()   #\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c HTTP \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u044b. \u0418\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e $http.Prefixes.Add(&quot;http:\/\/localhost\/&quot;) $http.Prefixes.Add(&quot;http:\/\/127.0.0.1\/&quot;)    #\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0432\u0435\u0431 \u043b\u0438\u0441\u0442\u0435\u043d\u0435\u0440 $http.Start()   if ($http.IsListening) {     Write-Host &quot;\u0421\u043a\u0440\u0438\u043f\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d&quot; }   while ($http.IsListening) {       #GetContext \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u044b\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 HttpListener     $context = $http.GetContext()       #\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0442\u0438\u043f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Request.HttpMethod      if ($context.Request.HttpMethod -eq 'POST') {           #\u0427\u0438\u0442\u0430\u0435\u043c \u0441\u044b\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 GetContext         #\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0432\u043e\u0439 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440         [System.IO.StreamReader]::new($context.Request.InputStream).ReadToEnd() | ForEach-Object {                          #\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e System.Web.HttpUtility \u0434\u0435\u043b\u0430\u0435\u043c urlDecore, \u0438\u043d\u0430\u0447\u0435 \u043a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0443\u043d\u044b             $DecodedContent = [System.Web.HttpUtility]::UrlDecode($_)               #\u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u0438\u043b\u0435\u0442\u0435\u0432\u0448\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u0444\u043e\u0440\u043c\u0430\u0442             $ConvertedForm = $DecodedContent | ConvertFrom-Json -ErrorAction SilentlyContinue               #C\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439             $ConvertedForm | Format-Table                     }           #\u041e\u0442\u0432\u0435\u0447\u0430\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0443 200 OK \u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u0438\u043c.         $context.Response.Headers.Add(&quot;Content-Type&quot;, &quot;text\/plain&quot;)         $context.Response.StatusCode = 200         $ResponseBuffer = [System.Text.Encoding]::UTF8.GetBytes(&quot;&quot;)         $context.Response.ContentLength64 = $ResponseBuffer.Length         $context.Response.OutputStream.Write($ResponseBuffer, 0, $ResponseBuffer.Length)         $context.Response.Close()       }     #C\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439     $http.Close()     break } <\/code><\/pre>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u043a\u0438 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437 JSON \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b.<\/p>\n<p>  \u0410\u0432\u0442\u043e\u0440 \u043d\u0430\u0434\u0435\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u044b \u0432\u044b\u0431\u0440\u043e\u0441\u0438\u0442\u0435 Postman, \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 GIT \u0441 GUI.<\/p>\n<p>  <a href=\"http:\/\/ruvds.com\/ru-rub?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=ilya&amp;utm_content=powershell-as-c#order\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ou\/g5\/kh\/oug5kh6sjydt9llengsiebnp40w.png\"><\/a><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/513900\/\"> https:\/\/habr.com\/ru\/company\/ruvds\/blog\/513900\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/513900\/\"><a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/513900\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/js\/yc\/na\/jsycnamvumej2vknuwh2jqsibe4.png\"><\/div>\n<p><\/a><br \/>  Powershell \u2014 \u0443\u0434\u043e\u0431\u043d\u0430\u044f API \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u043d\u0430 .net. Powershell \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442\u044b, \u043d\u0435 \u0443\u043f\u0438\u0440\u0430\u044f\u0441\u044c \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u044f \u0441\u0445\u043e\u0436\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u041a\u0414\u0412\u041f, \u0430\u0432\u0442\u043e\u0440 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442 \u043f\u043e\u0437\u0436\u0435 \u043f\u043e \u0442\u0435\u043a\u0441\u0442\u0443. \u0421\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u043c \u0441\u0440\u043e\u0447\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0442\u0432\u043e\u0440\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u043d\u0430 C#.<\/p>\n<p>  TL;DR: Postman \u043d\u0435 \u043d\u0443\u0436\u0435\u043d, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c Powershell. \u041d\u043e \u0441\u043f\u0435\u0440\u0432\u0430 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0439\u0442\u0438 \u0438\u0437\u0434\u0430\u043b\u0435\u043a\u0430.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-308046","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=308046"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308046\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}