<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Powershell - TheCodeBuzz</title>
	<atom:link href="https://thecodebuzz.com/category/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>https://thecodebuzz.com</link>
	<description>Best Practices for Software Development</description>
	<lastBuildDate>Sat, 09 Mar 2024 22:15:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://thecodebuzz.com/wp-content/uploads/2022/11/cropped-android-chrome-512x512-1-1-51x51.jpg</url>
	<title>Powershell - TheCodeBuzz</title>
	<link>https://thecodebuzz.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Use JSON array fields in a PowerShell script</title>
		<link>https://thecodebuzz.com/powershell-generate-json-array-or-list/</link>
					<comments>https://thecodebuzz.com/powershell-generate-json-array-or-list/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 04 Oct 2023 23:27:00 +0000</pubDate>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[convertfrom-json]]></category>
		<category><![CDATA[powershell add json object to array]]></category>
		<category><![CDATA[powershell convertto-json array]]></category>
		<category><![CDATA[powershell create json object]]></category>
		<category><![CDATA[powershell get json value by key]]></category>
		<category><![CDATA[powershell json array foreach]]></category>
		<category><![CDATA[powershell json parsing]]></category>
		<category><![CDATA[powershell read json array]]></category>
		<category><![CDATA[powershell-generate-json]]></category>
		<category><![CDATA[powershell-generate-json-array]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=16612</guid>

					<description><![CDATA[<p>PowerShell Script- Using JSON Array or List Today in this article, we shall see how to generate or how to use Use JSON array fields in a PowerShell script. This conversion is often needed when you are trying to perform GET or POST requests with body parameters to understand examples. Let&#8217;s use the below sample [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/powershell-generate-json-array-or-list/">Use JSON array fields in a PowerShell script</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading"><strong>PowerShell Script- Using JSON Array or List</strong></h1>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="438" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/making-a-powershell-post-request-using-body-1-1024x438.jpg" alt="PowerShell Script- Using JSON Array or List" class="wp-image-16631" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-powershell-post-request-using-body-1-1024x438.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-powershell-post-request-using-body-1-300x128.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-powershell-post-request-using-body-1-768x328.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-powershell-post-request-using-body-1-785x336.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-powershell-post-request-using-body-1.jpg 1532w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Today in this article, we shall see how to generate or how to use Use JSON array fields in a PowerShell script.</p>



<p></p>



<p>This conversion is often needed when you are trying to perform GET or POST requests with body parameters to understand examples.</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-example-input">Sample JSON Input</a></li><li><a href="#aioseo-convertfrom-json--inputobject-json">ConvertFrom-Json -InputObject $json</a></li><li><a href="#aioseo-convertto-json--inputobject-body">ConvertTo-Json -InputObject $body</a></li><li><a href="#aioseo-send-array-in-post-request">Send Array in POST Request</a><ul><li><a href="#aioseo-example-1">Example 1</a></li><li><a href="#aioseo-example-2">Example 2</a></li></ul></li></ul></div>



<p></p>



<p>Let&#8217;s use the below sample JSON which we want to represent/Generate in the PowerShell script.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-example-input">Sample JSON Input</h2>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [5,6,7,10,11,12,13,14,15,16,17]; title: ; notranslate">
{
    &quot;siteUrl&quot;: &quot;https://www.thecodebuzz.com&quot;,
    &quot;email&quot;: &quot;info@thecodebuzz.com&quot;,
    &quot;itemList&quot;: &#x5B;
        &quot;Item1&quot;,
        &quot;Item2&quot;,
        &quot;Item3&quot;
    ],
    &quot;details&quot;: &#x5B;
        {
            &quot;name&quot;: &quot;test&quot;,
            &quot;id&quot;: &quot;213124&quot;
        },
        {
            &quot;name&quot;: &quot;test2&quot;,
            &quot;id&quot;: &quot;453534&quot;
        }
    ]
}
</pre></div>


<p></p>



<p></p>



<p>As shown above, we are dealing with two types of array i.e <strong><em>itemList</em></strong> and <strong><em>details</em></strong>.</p>



<p></p>



<p>We can very much create a Powershell script equivalent of the above JSON sample as below,</p>



<p></p>



<p></p>



<p>As we can see regular <strong>Array </strong>can be represented as,</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [1]; title: ; notranslate">
  &#039;urlList&#039;= @(
                    &quot;item1&quot;,
                    &quot;item2&quot;,
                    &quot;item3&quot;,
                    &quot;item4&quot;
                )
</pre></div>


<p></p>



<p>For complex array is represented(representing object or complex type)  as below,</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [1]; title: ; notranslate">
 &#039;details&#039;=@(
                 @{
                  &quot;name&quot;= &quot;test&quot;
                  &quot;id&quot;= &quot;213124&quot;
                 },
                 @{
                  &quot;name&quot;= &quot;test2&quot;
                  &quot;id&quot;= &quot;64564&quot;
                 }
              )
</pre></div>


<p></p>



<h2 class="wp-block-heading" id="aioseo-convertfrom-json--inputobject-json"><strong>ConvertFrom-Json -InputObject $json</strong></h2>



<p></p>



<p>The above commands will convert JSON to Windows PowerShell objects.</p>



<p></p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="132" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/json-array-in-powershell-1024x132.jpg" alt="Use JSON array in PowerShell script" class="wp-image-16615" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/json-array-in-powershell-1024x132.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/06/json-array-in-powershell-300x39.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/06/json-array-in-powershell-768x99.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/json-array-in-powershell-1536x197.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/06/json-array-in-powershell-2048x263.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2021/06/json-array-in-powershell-785x101.jpg 785w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p><strong>Below is the final PowerShell script,</strong></p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
$body = @{
    &#039;siteUrl&#039; =&quot;https://www.thecodebuzz.com&quot;
    &#039;urlList&#039;= @(
                    &quot;item1&quot;,
                    &quot;item2&quot;,
                    &quot;item3&quot;,
                    &quot;item4&quot;
                )

   &#039;details&#039;=@(
                 @{
                  &quot;name&quot;= &quot;test&quot;
                  &quot;id&quot;= &quot;213124&quot;
                 },
                 @{
                  &quot;name&quot;= &quot;test2&quot;
                  &quot;id&quot;= &quot;64564&quot;
                 }
              )
}
</pre></div>


<p></p>



<h2 class="wp-block-heading" id="aioseo-convertto-json--inputobject-body"><strong>ConvertTo-Json -InputObject $body</strong></h2>



<p></p>



<p>The above utility method i.e <strong><a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertto-json?view=powershell-7.1" target="_blank" rel="noreferrer noopener">ConvertTo-Json</a></strong> will produce the JSON string that we started with above confirming our representation in the form of ps script is correct.</p>



<p></p>



<p></p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="705" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/generate-json-array-in-powershell-1024x705.jpg" alt="Use JSON array fields in a PowerShell script" class="wp-image-16616" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/generate-json-array-in-powershell-1024x705.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/06/generate-json-array-in-powershell-300x206.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/06/generate-json-array-in-powershell-768x528.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/generate-json-array-in-powershell-1536x1057.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/06/generate-json-array-in-powershell-756x520.jpg 756w, https://thecodebuzz.com/wp-content/uploads/2021/06/generate-json-array-in-powershell.jpg 1731w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<h2 class="wp-block-heading" id="aioseo-send-array-in-post-request">Send Array in POST Request</h2>



<p></p>



<p>PowerShell JSON Array examples as below.</p>



<p></p>



<p></p>



<h3 class="wp-block-heading" id="aioseo-example-1"><strong>Example </strong>1</h3>



<p></p>



<pre class="wp-block-preformatted"># Sample array of strings
$array = @("A", "B", "C")

# Convert the array to JSON format
$jsonBody = $array | ConvertTo-Json

# API endpoint URL
$apiUrl = "https://www.thecodebuzz.com/api/"

# Send the POST request with the array as the request body

$response = Invoke-RestMethod -Uri $apiUrl -Method Post -Body $jsonBody -ContentType "application/json"

# Display the response
$response




</pre>



<h3 class="wp-block-heading" id="aioseo-example-2">Example 2</h3>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
$body = @{
    &#039;siteUrl&#039; = &quot;https://www.thecodebuzz.com&quot;
    &#039;urlList&#039;= @(
        &quot;Item1&quot;,
        &quot;Item2&quot;,
        &quot;Item3&quot;)     
}
</pre></div>


<p></p>



<p>Here is the request format,</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -Headers $headers -ContentType "application/json"</pre>



<p></p>



<p><strong><em>References:</em></strong></p>



<p></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/making-powershell-post-request-with-body-json-array/" title="Making a PowerShell POST request with body" target="_blank" rel="noreferrer noopener"><strong><em>Making a PowerShell POST request with body</em></strong></a></li>
</ul>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p><p>The post <a href="https://thecodebuzz.com/powershell-generate-json-array-or-list/">Use JSON array fields in a PowerShell script</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/powershell-generate-json-array-or-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Make PowerShell POST Request With Body</title>
		<link>https://thecodebuzz.com/making-powershell-post-request-with-body-json-array/</link>
					<comments>https://thecodebuzz.com/making-powershell-post-request-with-body-json-array/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 19 Sep 2023 20:43:00 +0000</pubDate>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[invoke-webrequest]]></category>
		<category><![CDATA[invoke-webrequest body]]></category>
		<category><![CDATA[invoke-webrequest get response body]]></category>
		<category><![CDATA[invoke-webrequest post example]]></category>
		<category><![CDATA[invoke-webrequest post form data]]></category>
		<category><![CDATA[post PowerShell example]]></category>
		<category><![CDATA[powershell invoke-restmethod json body]]></category>
		<category><![CDATA[powershell post]]></category>
		<category><![CDATA[PowerShell POST example]]></category>
		<category><![CDATA[PowerShell POST request]]></category>
		<category><![CDATA[powershell post request with file]]></category>
		<category><![CDATA[powershell post request with json body]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=16600</guid>

					<description><![CDATA[<p>Making a PowerShell POST request with body &#8211; Guidelines Today in this article, we shall learn how to Make PowerShell POST request with body parameters using easy-to-understand examples. Please note that we can use Invoke-WebRequest or Invoke-RestMethod to achieve the same. In PowerShell, you can use the Invoke-RestMethod or Invoke-WebRequest cmdlet to send a POST [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/making-powershell-post-request-with-body-json-array/">Make PowerShell POST Request With Body</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading"><strong>Making a PowerShell POST request with body &#8211; Guidelines</strong></h1>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="388" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/making-a-powershell-post-request-using-body-1024x388.jpg" alt="PowerShell POST request with body  Invoke-RestMethod " class="wp-image-16607" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-powershell-post-request-using-body-1024x388.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-powershell-post-request-using-body-300x114.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-powershell-post-request-using-body-768x291.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-powershell-post-request-using-body-1536x582.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-powershell-post-request-using-body-785x297.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-powershell-post-request-using-body.jpg 1729w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Today in this article, we shall learn how to Make <strong>PowerShell POST </strong>request with body parameters using easy-to-understand examples.</p>



<p></p>



<p>Please note that we can use Invoke-WebRequest or Invoke-RestMethod to achieve the same. </p>



<p></p>



<p>In PowerShell, you can use the <strong><code>Invoke-RestMethod</code>  or Invoke-WebRequest </strong>cmdlet to send a POST request with a simple object or array as the request body. </p>



<p></p>



<p>One can easily use these cmdlets to create powerful PowerShell-based API or PowerShell Web Services calls. This CMDLet helps you write PowerShell REST Client-side code.</p>



<p></p>



<p>We shall cover the below examples,</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-powershell-post-request-with-body">PowerShell POST request with body</a></li><li><a href="#aioseo-powershell-post-request-with-body-with-headers">PowerShell POST request with the body with Headers</a></li><li><a href="#aioseo-using-array-in-request-body-using-powershell">Send Array in POST Request- Using Simple Array in request Body using Powershell</a></li><li><a href="#aioseo-using-array-key-value-pairs-in-request-body-using-powershell">Send Array in POST Request</a></li><li><a href="#aioseo-differences-between-invoke-restmethod-vs-invoke-webrequest">Differences between Invoke-RestMethod Vs Invoke-WebRequest</a></li></ul></div>



<p></p>



<h2 class="wp-block-heading" id="aioseo-powershell-post-request-with-body">PowerShell POST request with body</h2>



<p></p>



<p>Below is the expected body parameter in the form of JSON,</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
{
    &quot;siteUrl&quot;: &quot;https://www.thecodebuzz.com&quot;,
    &quot;email&quot;: &quot;infoATthecodebuzz.com&quot;
}
</pre></div>


<p></p>



<p>We shall use <strong><a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.1" target="_blank" rel="noreferrer noopener">Invoke-RestMethod</a> </strong>to use the above request body and send it in the POST body parameter,</p>



<p></p>



<p>Below is an equivalent body parameter example in PowerShell,</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [1]; title: ; notranslate">
$body = @{
    &quot;siteUrl&quot; =&quot;https://www.thecodebuzz.com&quot;
    &quot;email&quot; = &quot;infoATthecodebuzz.com&quot;
}
</pre></div>


<p></p>



<p>Below is the POST method example using<strong> Invoke-RestMethod</strong>,</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -ContentType "application/json"

</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="258" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/how-to-create-a-raw-body-for-post-request-using-powershell-1024x258.jpg" alt="how-to-do-a-webrequest-with-json-body-containing-arrays-or-lists- Invoke-RestMethod " class="wp-image-16601" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/how-to-create-a-raw-body-for-post-request-using-powershell-1024x258.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/06/how-to-create-a-raw-body-for-post-request-using-powershell-300x76.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/06/how-to-create-a-raw-body-for-post-request-using-powershell-768x194.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/how-to-create-a-raw-body-for-post-request-using-powershell-1536x387.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/06/how-to-create-a-raw-body-for-post-request-using-powershell-785x198.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/06/how-to-create-a-raw-body-for-post-request-using-powershell.jpg 1988w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p>Below is the POST method example using<strong> Invoke-WebRequest</strong>,</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size"><strong>Invoke-WebRequest</strong> -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -ContentType "application/json"</pre>



<p></p>



<h2 class="wp-block-heading" id="aioseo-powershell-post-request-with-body-with-headers">PowerShell POST request with the body with Headers</h2>



<p></p>



<p>Powershell requests with headers can be defined as below,</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [1]; title: ; notranslate">
$headers = @{
 &#039;Content-Type&#039;=&#039;application/json&#039;
 &#039;apikey&#039;=&#039;7bd43dc4216e15971&#039;
 }

</pre></div>


<p></p>



<p>Below is the Powershell POST method example with Headers,</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -Headers $headers -ContentType "application/json"</pre>



<p></p>



<h2 class="wp-block-heading" id="aioseo-using-array-in-request-body-using-powershell">Send Array in POST Request- Using Simple Array in request Body using Powershell</h2>



<p></p>



<p>One can use Array in request Body using Powershell. We can easily send Array Data in REST API.</p>



<p></p>



<p>When sending an array in the request body, you need to convert it to <strong><em>JSON </em></strong>format.</p>



<p></p>



<p>Here we need to use $(..) to represent an array.</p>



<p></p>



<p><strong>Example 1</strong></p>



<p></p>



<p>I have a <strong><em>sample JSON</em></strong> with an array example as below,</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [4,5,6,7]; title: ; notranslate">
{
    &quot;siteUrl&quot;: &quot;https://www.thecodebuzz.com&quot;,
    &quot;email&quot; : &quot;infoATthecodebuzz.com&quot;,
    &quot;itemList&quot;: &#x5B;
        &quot;Item1&quot;,
        &quot;Item2&quot;,
        &quot;Item3&quot;],
    &quot;details&quot;:&#x5B;
         {    
          name:&quot;test&quot;,
          id: &quot;213124&quot;
          }]
}
</pre></div>


<p></p>



<p>The PowerShell request body for <strong><em>Array </em></strong>looks as below,</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
$body = @{
    &#039;siteUrl&#039; = &quot;https://www.thecodebuzz.com&quot;
    &#039;urlList&#039;= @(
        &quot;Item1&quot;,
        &quot;Item2&quot;,
        &quot;Item3&quot;)     
}
</pre></div>


<p></p>



<p>Here is the request format,</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -Headers $headers -ContentType "application/json"</pre>



<p></p>



<p>Below is the POST method example using<strong> Invoke-WebRequest</strong>,</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size"><strong>Invoke-WebRequest</strong> -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -Headers $headers -ContentType "application/json"
 </pre>



<p><strong>Example 2</strong></p>



<pre class="wp-block-preformatted"># Sample array of strings
$array = @("A", "B", "C")

# Convert the array to JSON format
$jsonBody = $array | ConvertTo-Json

# API endpoint URL
$apiUrl = "https://www.thecodebuzz.com/api/"

# Send the POST request with the array as the request body

$response = Invoke-RestMethod -Uri $apiUrl -Method Post -Body $jsonBody -ContentType "application/json"

# Display the response
$response
</pre>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-using-array-key-value-pairs-in-request-body-using-powershell">Send Array in POST Request </h2>



<p></p>



<p>Using Array (key-Value pairs) in request Body using Powershell</p>



<p></p>



<p>$body = @{<br>&#8216;siteUrl&#8217; = &#8220;https://www.thecodebuzz.com&#8221;<br>&#8216;urlList&#8217;= @(<br>{&#8220;Item1&#8243;=&#8221;value1&#8221;},<br>{&#8220;Item2&#8243;=&#8221;value2&#8221;},<br>{&#8220;Item3&#8243;=&#8221;value3&#8221;})<br>}</p>



<p></p>



<p>Here is the POST example request format,</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -Headers $headers -ContentType "application/json"</pre>



<p><br><br></p>



<h2 class="wp-block-heading" id="aioseo-differences-between-invoke-restmethod-vs-invoke-webrequest">Differences between<a href="https://www.thecodebuzz.com/invoke-restmethod-get-post-example-with-parameters/" target="_blank" rel="noopener" title="Powershell Invoke-RestMethod GET and POST Example"> <code><code>Invoke-RestMethod</code></code> Vs Invoke-WebRequest</a></h2>



<p></p>



<p><code>Invoke-RestMethod</code> efficiently deal with XML and JSON results. </p>



<p>It doesn&#8217;t support straight HTML(except XML-compliant HTML)  while <code>Invoke-WebRequest</code> efficiently deal with straight Web/HTML results.</p>



<p></p>



<p>For <em><strong>additional differences</strong></em> and guidelines, please visit <a href="https://www.thecodebuzz.com/invoke-webrequest-vs-invoke-restmethod-differences/" target="_blank" rel="noopener" title="Differences Invoke-WebRequest Vs Invoke-RestMethod"><strong>this </strong></a>article.</p>



<p></p>



<p></p>



<p>For more details on handling array or JSON please refer to the below article,</p>



<p></p>



<p><strong><em>HTTP/WebRequest using JSON body with <a href="https://www.thecodebuzz.com/python-split-array-list-evenly-chunks/">array or list</a></em></strong> </p>



<p></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/powershell-generate-json-array-or-list/" target="_blank" rel="noreferrer noopener" title="PowerShell Script- Using JSON Array or List"><strong><em>PowerShell Script- Using JSON Array or List</em></strong></a></li>
</ul>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/making-powershell-post-request-with-body-json-array/">Make PowerShell POST Request With Body</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/making-powershell-post-request-with-body-json-array/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Task scheduler PowerShell example and guidelines</title>
		<link>https://thecodebuzz.com/schedule-powershell-script-using-windows-task-scheduler/</link>
					<comments>https://thecodebuzz.com/schedule-powershell-script-using-windows-task-scheduler/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 22 Jun 2022 14:35:00 +0000</pubDate>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[automate powershell script without task scheduler]]></category>
		<category><![CDATA[create task scheduler powershell]]></category>
		<category><![CDATA[powershell script to create scheduled task with credentials]]></category>
		<category><![CDATA[PowerShell Script using Windows Task Scheduler]]></category>
		<category><![CDATA[PowerShell Script Windows Task Scheduler]]></category>
		<category><![CDATA[powershell task]]></category>
		<category><![CDATA[PowerShell Task Scheduler]]></category>
		<category><![CDATA[PowerShell Windows Task Scheduler]]></category>
		<category><![CDATA[run powershell script automatically]]></category>
		<category><![CDATA[run powershell script from task scheduler with parameters]]></category>
		<category><![CDATA[schedule powershell script to run every hour]]></category>
		<category><![CDATA[task scheduler powershell script not running]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=16574</guid>

					<description><![CDATA[<p>Today in this article, we will see how to use Task Scheduler PowerShell with an example. We will schedule PowerShell Script using Windows Task Scheduler and automate PowerShell script execution. Today in this article, we shall see below There are many advantages of the Tasks scheduler, some of which are listed below, Let’s see in [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/schedule-powershell-script-using-windows-task-scheduler/">Task scheduler PowerShell example and guidelines</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<figure class="wp-block-image size-large"><a href="https://www.thecodebuzz.com/schedule-powershell-script-using-windows-task-scheduler/" target="_blank" rel="noopener"><img loading="lazy" decoding="async" width="1024" height="406" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/schedule-powershell-scripts-task-scheduler-daily-task-1024x406.jpg" alt="how-to-run-a-powershell-script" class="wp-image-16585" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/schedule-powershell-scripts-task-scheduler-daily-task-1024x406.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/06/schedule-powershell-scripts-task-scheduler-daily-task-300x119.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/06/schedule-powershell-scripts-task-scheduler-daily-task-768x305.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/schedule-powershell-scripts-task-scheduler-daily-task-1536x609.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/06/schedule-powershell-scripts-task-scheduler-daily-task-785x311.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/06/schedule-powershell-scripts-task-scheduler-daily-task.jpg 1631w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></figure>



<p>Today in this article, we will see how to use Task Scheduler PowerShell with an example. We will schedule <strong><em>PowerShell </em></strong>Script using Windows Task Scheduler and automate PowerShell script execution.</p>



<p></p>



<p>Today in this article, we shall see below</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-create-tasks-in-task-scheduler">Create Tasks Scheduler PowerShell Job</a></li><li><a href="#aioseo-define-general-configuration-for-powershell-job">Define general configuration for Powershell Job</a></li><li><a href="#aioseo-configure-the-tasks-in-task-scheduler">Configure Powershell Tasks in the Task Scheduler</a></li><li><a href="#aioseo-configure-powershell-action-in-task-scheduler">Configure Action in Task scheduler PowerShell</a></li><li><a href="#aioseo-configure-condition-in-task-scheduler">Configure Condition in Task Scheduler</a></li></ul></div>



<p></p>



<p></p>



<p>There are many advantages of the Tasks scheduler, some of which are listed below,</p>



<p></p>



<ul class="wp-block-list">
<li><em>Automate the Job/Task</em></li>



<li><em>Schedule tasks at a predefined schedule.</em></li>



<li><em>Schedule the task as per predefined priority.</em></li>



<li><em>Improves turnaround time by a running script at a convenient time. like nightly runs etc.</em></li>
</ul>



<p></p>



<p>Let’s see in detail, how to schedule the PowerShell script through the Task scheduler.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-create-tasks-in-task-scheduler">Create Tasks Scheduler PowerShell Job</h2>



<p></p>



<p>Open the Tasks Scheduler Windows -&gt; search for <em><strong>Task scheduler</strong></em> or type <em><strong>taskschd.msc</strong></em> using Windows+R.</p>



<p></p>



<figure class="wp-block-image size-large is-resized"><a href="https://www.thecodebuzz.com/schedule-powershell-script-using-windows-task-scheduler/" target="_blank" rel="noopener"><img loading="lazy" decoding="async" width="1024" height="385" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-with-task-scheduler-1024x385.jpg" alt="Tasks Scheduler PowerShell" class="wp-image-16575" style="width:456px;height:171px" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-with-task-scheduler-1024x385.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-with-task-scheduler-300x113.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-with-task-scheduler-768x289.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-with-task-scheduler-785x295.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-with-task-scheduler.jpg 1477w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></figure>



<p></p>



<p><strong>Click on &#8220;Create Task&#8221;</strong></p>



<p></p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="671" height="698" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/create-task-in-scheduler.jpg" alt="schedule powershell script task scheduler" class="wp-image-16576" style="width:274px;height:285px" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/create-task-in-scheduler.jpg 671w, https://thecodebuzz.com/wp-content/uploads/2021/06/create-task-in-scheduler-288x300.jpg 288w, https://thecodebuzz.com/wp-content/uploads/2021/06/create-task-in-scheduler-500x520.jpg 500w" sizes="auto, (max-width: 671px) 100vw, 671px" /></figure>



<p></p>



<h2 class="wp-block-heading" id="aioseo-define-general-configuration-for-powershell-job">Define general configuration for Powershell Job </h2>



<p></p>



<p>Define the below attributes,</p>



<ul class="wp-block-list">
<li><strong>Name </strong>&#8211; Define Application Name, </li>



<li><strong>Description </strong>&#8211; Define a description of the task</li>



<li>Security options- Please select the appropriate Radio button. We shall select the option &#8220;Run whether the user is logged on or not&#8221;
<ul class="wp-block-list">
<li><strong>Run with the highest privileges</strong> &#8211; To run the program with <strong><em>administrator privileges</em></strong>, its recommended to use this option</li>
</ul>
</li>
</ul>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="774" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/configure-task-in-windows-task-scheduler-1024x774.jpg" alt="PowerShell Script using Windows Task Scheduler" class="wp-image-16577" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/configure-task-in-windows-task-scheduler-1024x774.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/06/configure-task-in-windows-task-scheduler-300x227.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/06/configure-task-in-windows-task-scheduler-768x581.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/configure-task-in-windows-task-scheduler-688x520.jpg 688w, https://thecodebuzz.com/wp-content/uploads/2021/06/configure-task-in-windows-task-scheduler.jpg 1264w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<h2 class="wp-block-heading" id="aioseo-configure-the-tasks-in-task-scheduler">Configure Powershell Tasks in the Task Scheduler</h2>



<p></p>



<p><strong>Click on the &#8220;Trigger&#8221; tab and define the configuration</strong></p>



<p></p>



<p>In the next step, please click on the &#8220;<strong>Trigger</strong>&#8221; tab and click on &#8220;New&#8221; to create a new trigger.</p>



<p>You can define the condition of when to trigger the given task for example &#8220;On a schedule&#8221; or &#8220;On an event&#8221;  or &#8220;on logon&#8221; or &#8220;on an event&#8221; etc.</p>



<p></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="640" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-with-task-scheduler-daily-task-1024x640.jpg" alt=" Run Powershell script using task scheduler to " class="wp-image-16578" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-with-task-scheduler-daily-task-1024x640.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-with-task-scheduler-daily-task-300x187.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-with-task-scheduler-daily-task-768x480.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-with-task-scheduler-daily-task-1536x960.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-with-task-scheduler-daily-task-785x490.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-with-task-scheduler-daily-task.jpg 1708w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<h2 class="wp-block-heading" id="aioseo-configure-powershell-action-in-task-scheduler">Configure Action in Task scheduler PowerShell </h2>



<p></p>



<p><strong>Click on the &#8220;Action&#8221; tab and define the configuration</strong></p>



<p></p>



<p>In the next step, please click on the &#8220;<strong><strong>Action</strong></strong>&#8221; tab and click on &#8220;New&#8221; to create a new action.</p>



<p></p>



<p>Please specify the following parameters:</p>



<ul class="wp-block-list">
<li><strong>Action:&nbsp;</strong>Start a program</li>



<li><strong>Program\script:</strong>&nbsp;Powershell</li>



<li><strong>Add arguments (optional):</strong>&nbsp;-file&nbsp;<em>[script path]</em></li>
</ul>



<p></p>



<p>I have kept my script at the below path,</p>



<p></p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="210" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/how-to-automate-powershell-scripts-with-task-scheduler-1024x210.jpg" alt="run powershell script using task scheduler" class="wp-image-16582" style="width:506px;height:103px" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/how-to-automate-powershell-scripts-with-task-scheduler-1024x210.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/06/how-to-automate-powershell-scripts-with-task-scheduler-300x62.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/06/how-to-automate-powershell-scripts-with-task-scheduler-768x158.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/how-to-automate-powershell-scripts-with-task-scheduler-785x161.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/06/how-to-automate-powershell-scripts-with-task-scheduler.jpg 1294w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="913" height="1005" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/schedule-powershell-script-task-scheduler.jpg" alt="Schedule PowerShell Script using Windows Task Scheduler" class="wp-image-16579" style="width:470px;height:517px" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/schedule-powershell-script-task-scheduler.jpg 913w, https://thecodebuzz.com/wp-content/uploads/2021/06/schedule-powershell-script-task-scheduler-273x300.jpg 273w, https://thecodebuzz.com/wp-content/uploads/2021/06/schedule-powershell-script-task-scheduler-768x845.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/schedule-powershell-script-task-scheduler-472x520.jpg 472w" sizes="auto, (max-width: 913px) 100vw, 913px" /></figure>



<p></p>



<h2 class="wp-block-heading" id="aioseo-configure-condition-in-task-scheduler">Configure Condition in Task Scheduler  </h2>



<p></p>



<p><strong>Click on the &#8220;Condition&#8221; tab and define the configuration</strong></p>



<p></p>



<p>In the next step, please click on the &#8220;<strong><strong><strong>Condition</strong></strong></strong>&#8221; tab and select the appropriate options.</p>



<p></p>



<p>These additional conditions let you configure the task based on a specified selection. The task will not run if any conditions specified here are not met&#8230;</p>



<p></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="779" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-task-scheduler-daily-task-1024x779.jpg" alt="run powershell script using task scheduler,Task scheduler PowerShell " class="wp-image-16581" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-task-scheduler-daily-task-1024x779.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-task-scheduler-daily-task-300x228.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-task-scheduler-daily-task-768x584.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-task-scheduler-daily-task-684x520.jpg 684w, https://thecodebuzz.com/wp-content/uploads/2021/06/automate-powershell-scripts-task-scheduler-daily-task.jpg 1260w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p>Once configured, You should be able to run the PowerShell script using the task scheduler.</p>



<p></p>



<p><strong>Reference </strong>:</p>



<p></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/making-powershell-post-request-with-body-json-array/" title="Making a PowerShell POST request with body" target="_blank" rel="noreferrer noopener"><strong><em>Making a PowerShell POST request with body</em></strong></a></li>
</ul>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p><p>The post <a href="https://thecodebuzz.com/schedule-powershell-script-using-windows-task-scheduler/">Task scheduler PowerShell example and guidelines</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/schedule-powershell-script-using-windows-task-scheduler/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Powershell Upload, Download file Google Cloud Storage Bucket</title>
		<link>https://thecodebuzz.com/powershell-script-upload-download-file-google-cloud-storage-bucket/</link>
					<comments>https://thecodebuzz.com/powershell-script-upload-download-file-google-cloud-storage-bucket/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 13 Mar 2022 03:16:00 +0000</pubDate>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Download file Google Cloud Storage Bucket]]></category>
		<category><![CDATA[Powershell Upload]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=21351</guid>

					<description><![CDATA[<p>Powershell Upload, Download file Google Storage Bucket Today in this article we will see how to automate and perform Powershell Upload, Download file Google cloud Storage Bucket Today in this article, we will cover below aspects, Getting Started Prerequisites Create an account&#160;in the google cloud project. Install the Google Cloud SDK Above google cloud SDK [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/powershell-script-upload-download-file-google-cloud-storage-bucket/">Powershell Upload, Download file Google Cloud Storage Bucket</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">Powershell Upload, Download file Google Storage Bucket</h1>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="351" src="https://www.thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-Upload-file-Google-Storage-Bucket-using-gsutil-1024x351.jpg" alt="Powershell Upload, Download file Google Cloud Storage Bucket" class="wp-image-21368" srcset="https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-Upload-file-Google-Storage-Bucket-using-gsutil-1024x351.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-Upload-file-Google-Storage-Bucket-using-gsutil-300x103.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-Upload-file-Google-Storage-Bucket-using-gsutil-768x263.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-Upload-file-Google-Storage-Bucket-using-gsutil-1536x526.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-Upload-file-Google-Storage-Bucket-using-gsutil-785x269.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-Upload-file-Google-Storage-Bucket-using-gsutil.jpg 1682w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Today in this article we will see how to automate and perform Powershell Upload, Download file Google cloud Storage Bucket</p>



<p>Today in this article, we will cover below aspects,</p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-getting-started">Getting Started</a></li><li><a href="#aioseo-prerequisites">Prerequisites</a></li><li><a href="#aioseo-powershell---upload-the-file-to-google-cloud-storage-bucket">Powershell &#8211; Upload the File to Google Cloud Storage Bucket</a></li><li><a href="#aioseo-powershell---download-the-file-to-google-cloud-storage-bucket">Powershell &#8211; Download the File to Google Cloud Storage Bucket</a></li></ul></div>



<h2 class="wp-block-heading" id="aioseo-getting-started">Getting Started  </h2>



<p></p>



<h2 class="wp-block-heading" id="aioseo-prerequisites">Prerequisites</h2>



<p></p>



<ul class="wp-block-list"><li><strong><em>Create an account&nbsp;in the google cloud project.</em></strong></li></ul>



<ul class="wp-block-list"><li><strong><em>Install the <a href="https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe" target="_blank" rel="noreferrer noopener">Google Cloud SDK</a></em></strong></li></ul>



<p></p>



<p>Above <strong><em>google cloud SDK </em></strong>needs to be installed on the Server or VM where we need to run the target scripts.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-powershell---upload-the-file-to-google-cloud-storage-bucket">Powershell &#8211; Upload the File to Google Cloud Storage Bucket </h2>



<p></p>



<p>Let&#8217;s use the below image(t<em>he official logo of the TheCodebuzz</em>) as an example. We shall be uploading this file to the GCP bucket.</p>



<p></p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.thecodebuzz.com/wp-content/uploads/2021/04/TheCodeBuzz.jpg" alt="Powershell Download file from google cloud storage bucket, Powershell Upload file from google cloud storage bucket" class="wp-image-15647" width="191" height="191" srcset="https://thecodebuzz.com/wp-content/uploads/2021/04/TheCodeBuzz.jpg 512w, https://thecodebuzz.com/wp-content/uploads/2021/04/TheCodeBuzz-300x300.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/04/TheCodeBuzz-150x150.jpg 150w" sizes="auto, (max-width: 191px) 100vw, 191px" /></figure>



<p></p>



<p>Let&#8217;s save the above file to the computer in the path <em><strong>C:\test\thecodebuzz.png</strong></em></p>



<p></p>



<p>Make sure to activate the service account as below by providing the service account file path as below,</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">gccloud auth activate-service-account --key-file $googleServiceAccount</pre>



<p></p>



<p><strong>Command Pattern</strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">gsutil cp [target-file-path] gs://[gcs-path]
</pre>



<p><strong>Example</strong></p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
try
{  
  #Source file path
  $sourFilePath = &quot;C:\test\CloudBlobTest.pdf&quot;
  #Google Service Account
  $googleServiceAccount = dir &quot;$sourFilePath\google-svc-thecodebuzz.json&quot;
  #Destination path
  $destinationPath = &quot;gs://thecodebuzz/&quot;
  #Activate the google service account
  gccloud auth activate-service-account --key-file $googleServiceAccount
  #Copy files to GCS bucket
  gsutil cp $sourFilePath $destinationPath

}

catch
{

  echo $_.Exception.GetType().FullName,$_.Exception.Message

}
</pre></div>


<p></p>



<p>After successful execution of the commands file will be uploaded to the google cloud storage bucket.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="490" src="https://www.thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-file-Google-Storage-Bucket-using-gsutil-1024x490.jpg" alt="Powershell Upload, Download file Google Storage Bucket" class="wp-image-21365" srcset="https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-file-Google-Storage-Bucket-using-gsutil-1024x490.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-file-Google-Storage-Bucket-using-gsutil-300x143.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-file-Google-Storage-Bucket-using-gsutil-768x367.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-file-Google-Storage-Bucket-using-gsutil-1536x734.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-file-Google-Storage-Bucket-using-gsutil-785x375.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-Download-file-Google-Storage-Bucket-using-gsutil.jpg 1602w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<h2 class="wp-block-heading" id="aioseo-powershell---download-the-file-to-google-cloud-storage-bucket">Powershell &#8211; Download the File to Google Cloud Storage Bucket  </h2>



<p></p>



<p>We shall now download the above-uploaded file from google Bucket using <em><strong>gsutil </strong></em>command line as below,</p>



<p></p>



<p><strong>Command Pattern</strong></p>



<p></p>



<pre id="block-64f0b9b2-afa3-40c0-a7a9-aa0091332cdb" class="wp-block-preformatted has-medium-font-size">gsutil cp gs://[gcs-file-path] [target-file-path]</pre>



<p></p>



<p><strong>Example</strong></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: powershell; title: ; notranslate">
try
{  
  #Source file path
  $sourFilePath = &quot;gs://thecodebuzz/load-from-gcutil/thecodebuzz.png&quot;
  #Google Service Account
  $googleServiceAccount = dir &quot;$sourFilePath\google-svc-thecodebuzz.json&quot;
  #Destination path
  $destinationPath = &quot;C:\Test\gcp\Download&quot;
  #Activate the google service account
  gccloud auth activate-service-account --key-file $googleServiceAccount
  #Copy files from GCS bucket
  gsutil cp $sourFilePath $destinationPath 

}

catch
{

  echo $_.Exception.GetType().FullName,$_.Exception.Message

}

</pre></div>


<p></p>



<p> Once the command is successful, you shall see the file generated in the path. </p>



<p></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="220" src="https://www.thecodebuzz.com/wp-content/uploads/2022/03/Powershell-gsutil-command-line-tool-upload-or-download-files-from-google-cloud-1024x220.jpg" alt="Powershell Download file Google Storage Bucket" class="wp-image-21366" srcset="https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-gsutil-command-line-tool-upload-or-download-files-from-google-cloud-1024x220.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-gsutil-command-line-tool-upload-or-download-files-from-google-cloud-300x64.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-gsutil-command-line-tool-upload-or-download-files-from-google-cloud-768x165.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-gsutil-command-line-tool-upload-or-download-files-from-google-cloud-1536x330.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-gsutil-command-line-tool-upload-or-download-files-from-google-cloud-785x169.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2022/03/Powershell-gsutil-command-line-tool-upload-or-download-files-from-google-cloud.jpg 1592w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<p></p>



<p><strong><em>References :</em></strong></p>



<p></p>



<ul class="has-medium-font-size wp-block-list"><li><a href="https://www.thecodebuzz.com/schedule-powershell-script-using-windows-task-scheduler/" target="_blank" rel="noreferrer noopener" title="Schedule PowerShell Script using Windows Task Scheduler"><em>Schedule PowerShell Script using Windows Task Scheduler</em></a></li></ul>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p><p>The post <a href="https://thecodebuzz.com/powershell-script-upload-download-file-google-cloud-storage-bucket/">Powershell Upload, Download file Google Cloud Storage Bucket</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/powershell-script-upload-download-file-google-cloud-storage-bucket/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Powershell Invoke-RestMethod GET and POST Example</title>
		<link>https://thecodebuzz.com/invoke-restmethod-get-post-example-with-parameters/</link>
					<comments>https://thecodebuzz.com/invoke-restmethod-get-post-example-with-parameters/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 03 Jan 2022 00:26:00 +0000</pubDate>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[invoke-restmethod : a parameter cannot be found that matches parameter]]></category>
		<category><![CDATA[invoke-restmethod authentication]]></category>
		<category><![CDATA[invoke-restmethod basic auth]]></category>
		<category><![CDATA[invoke-restmethod bearer token]]></category>
		<category><![CDATA[invoke-restmethod error handling]]></category>
		<category><![CDATA[Invoke-RestMethod GET Example]]></category>
		<category><![CDATA[Invoke-RestMethod POST Example]]></category>
		<category><![CDATA[invoke-restmethod response]]></category>
		<category><![CDATA[invoke-restmethod response headers]]></category>
		<category><![CDATA[invoke-restmethod vs invoke-webrequest]]></category>
		<category><![CDATA[invoke-restmethod where-object]]></category>
		<category><![CDATA[name 'authentication]]></category>
		<category><![CDATA[powershell invoke-restmethod json response]]></category>
		<category><![CDATA[powershell rest api authentication]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=16637</guid>

					<description><![CDATA[<p>Powershell Invoke-RestMethod GET and POST Example with parameters Today in this article, we shall see how to use the PowerShell invoke-restmethod utility method to perform API GET and POST requests with parameters. We shall cover below in today&#8217;s article, The&#160;Invoke-RestMethod&#160;cmdlet sends HTTP and HTTPS and also supports REST( Representational State transfer) requests to a WEB [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/invoke-restmethod-get-post-example-with-parameters/">Powershell Invoke-RestMethod GET and POST Example</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">Powershell Invoke-RestMethod GET and POST Example with parameters</h1>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="438" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/Invoke-RestMethod-get-post-request-using-body-examples-1024x438.jpg" alt="powershell invoke-restmethod,POST Example,powershell Invoke-RestMethod " class="wp-image-16696" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/Invoke-RestMethod-get-post-request-using-body-examples-1024x438.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/06/Invoke-RestMethod-get-post-request-using-body-examples-300x128.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/06/Invoke-RestMethod-get-post-request-using-body-examples-768x328.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/Invoke-RestMethod-get-post-request-using-body-examples-785x336.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/06/Invoke-RestMethod-get-post-request-using-body-examples.jpg 1532w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Today in this article, we shall see how to use the PowerShell <strong>invoke-restmethod </strong>utility method to perform API GET and POST requests with parameters. </p>



<p></p>



<p>We shall cover below in today&#8217;s article,</p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-powershell-invoke-restmethod-get-request">Powershell Invoke-RestMethod GET request</a></li><li><a href="#aioseo-invoke-restmethod-post-request">Powershell Invoke-RestMethod POST request</a></li><li><a href="#aioseo-invoke-restmethod-post-request-with-headers">Powershell Invoke-RestMethod POST request with Headers</a></li><li><a href="#aioseo-powershell-post-request-with-json-array-example">Powershell  Post request with JSON array example</a></li><li><a href="#aioseo-powershell-invoke-restmethod-post-request-with-authentication-headers">Powershell Invoke-RestMethod POST request with Authentication headers</a><ul><li><a href="#aioseo-jwt-bearer-authentication-using-powershell">JWT Bearer Authentication using Powershell</a></li><li><a href="#aioseo-basic-authentication-with-powershell">Basic Authentication with PowerShell</a></li></ul></li></ul></div>



<p></p>



<p></p>



<p>The&nbsp;<code><strong>Invoke-RestMethod</strong></code>&nbsp;<strong><em>cmdlet </em></strong>sends HTTP and HTTPS and also supports REST( Representational State transfer) requests to a WEB API or service. It efficiently deals with <strong><em>JSON and XML </em></strong>content.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-powershell-invoke-restmethod-get-request">Powershell Invoke-RestMethod GET request </h2>



<p></p>



<p>Below is the <strong>Invoke-RestMethod</strong> GET request example.</p>



<p></p>



<p><strong>Example</strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">PS C:\Test\File\load-sqldata&gt;  Invoke-RestMethod https://catfact.ninja/fact

fact                                                                                                                                                                     
----                                                                                                                                                                     
Researchers are unsure exactly how a cat purrs. Most veterinarians believe that a cat purrs by vibrating vocal folds deep in the throat. To do this, a muscle in the l..

</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="103" src="https://www.thecodebuzz.com/wp-content/uploads/2021/06/making-a-Invoke-RestMethod-get-post-request-using-body-1024x103.jpg" alt="Invoke-RestMethod POST with JWT bearer, invoke-restmethod" class="wp-image-16693" srcset="https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-Invoke-RestMethod-get-post-request-using-body-1024x103.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-Invoke-RestMethod-get-post-request-using-body-300x30.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-Invoke-RestMethod-get-post-request-using-body-768x78.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-Invoke-RestMethod-get-post-request-using-body-1536x155.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-Invoke-RestMethod-get-post-request-using-body-2048x207.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2021/06/making-a-Invoke-RestMethod-get-post-request-using-body-785x79.jpg 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<h2 class="wp-block-heading" id="aioseo-invoke-restmethod-post-request">Powershell Invoke-RestMethod POST request</h2>



<p></p>



<p>Let&#8217;s look at the <strong>Invoke-RestMethod</strong> POST request example below.</p>



<p></p>



<p>Below is an equivalent body parameter example in PowerShell,</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [1]; title: ; notranslate">
$body = @{
    &quot;siteUrl&quot; =&quot;https://www.thecodebuzz.com&quot;
    &quot;email&quot; = &quot;info1@thecodebuzz.com&quot;
}
</pre></div>


<p></p>



<p>Below is the POST method example using<strong>&nbsp;Invoke-RestMethod</strong>,</p>



<p></p>



<p><strong>Example</strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -Headers $headers -ContentType "application/json"</pre>



<p></p>



<h2 class="wp-block-heading" id="aioseo-invoke-restmethod-post-request-with-headers">Powershell Invoke-RestMethod POST request with Headers</h2>



<p></p>



<p>Let&#8217;s look at the <strong>Invoke-RestMethod</strong> POST request with headers example.</p>



<p></p>



<p>Powershell requests with headers can be defined as below,</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [1]; title: ; notranslate">
$headers = @{
 &#039;Content-Type&#039;=&#039;application/json&#039;
 &#039;apikey&#039;=&#039;475646456456&#039;
 }
</pre></div>


<p></p>



<p>Below is the <strong>Invoke-RestMethod</strong> POST method example with Headers,</p>



<p></p>



<p><strong>Example</strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -Headers $headers -ContentType "application/json"

</pre>



<h2 class="wp-block-heading" id="aioseo-powershell-post-request-with-json-array-example">Powershell  Post request with JSON array example </h2>



<p></p>



<p>Example here &#8211; <a href="https://www.thecodebuzz.com/powershell-generate-json-array-or-list/" target="_blank" rel="noopener" title="Use JSON array fields in a PowerShell script">Powershell  Post request with JSON array example </a></p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-powershell-invoke-restmethod-post-request-with-authentication-headers">Powershell Invoke-RestMethod POST request with Authentication headers</h2>



<p></p>



<p>Let&#8217;s look at the Invoke-RestMethod POST request with Authentication headers.</p>



<p></p>



<p>APIs require you to authenticate via different authentication schemes like,</p>



<p></p>



<ul class="wp-block-list">
<li>Basic authentication</li>
</ul>



<ul class="wp-block-list">
<li>OAuth token</li>
</ul>



<ul class="wp-block-list">
<li>JWT Bearer Authentication</li>
</ul>



<p></p>



<p>You can call Invoke-RestMethod POST request with Authentication headers like JWT bearer token as below,</p>



<p></p>



<h3 class="wp-block-heading" id="aioseo-jwt-bearer-authentication-using-powershell"><span style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">JWT Bearer Authentication using Powershell </span></h3>



<p></p>



<p><strong><em>JSON Web Token( JWT)</em></strong>&nbsp;is an open standard used for securely transmitting information between parties as a JSON object.&nbsp;</p>



<p>The client should always send the Authorization&nbsp;header with Bearer&nbsp;schema as below.</p>



<p><strong><em>Authorization: Bearer &lt;token&gt;</em></strong></p>



<p></p>



<p><strong>Example </strong>:</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJleHAiOjE1NzEwMDc3MzQsImlzcyI6Imh0dHBzOi8vbG9jYWxob3N0OjQ0MzQxIiwiYXVkIjoiaHR0cHM6Ly9sb2NhbGhvc3Q6NDQzNDEifQ.Ve2x6ueiHPyrP7wLjpmZrhx7QWrQKnkxWsu_1qUKKLA</pre>



<p></p>



<p>Below is how the header can be defined to send with any request.</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [4]; title: ; notranslate">
$token&quot;=&#039;xxxxxxxxxxx&#039;
$headers = @{
 &#039;Content-Type&#039;=&#039;application/json&#039;
 &#039;Authorization&#039;= &#039;Bearer $token&#039;
 }
</pre></div>


<p><strong>Example</strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -Headers $headers
</pre>



<p></p>



<h3 class="wp-block-heading" id="aioseo-basic-authentication-with-powershell"><span style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color">Basic Authentication with PowerShel</span>l</h3>



<p></p>



<p>Basic authentication&nbsp;is an Authentication Scheme built into the HTTP protocol which uses a simple username and password to access a restricted resource.</p>



<p></p>



<p>If you have&nbsp;<strong><em>UserName&nbsp;</em></strong>and&nbsp;<em><strong>Password&nbsp;</strong></em>is as “<em><strong>Test</strong></em>“, “<em><strong>Password</strong></em>” then Base64 string token should be as below,</p>



<p></p>



<p><strong>Authorization</strong>:&nbsp;<strong>Basic&nbsp;<em>VGVzdDpQYXNzd29yZA===</em></strong></p>



<p></p>



<p>Create base64 string using Powershell in detail in the below article,</p>



<p></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/invoke-webrequest-with-a-username-and-password-basic-authentication/" target="_blank" rel="noreferrer noopener" title="Invoke-WebRequest with a username and password – Basic authentication"><em><strong>Invoke-WebRequest with a username and password – Basic authentication</strong></em></a></li>
</ul>



<p></p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [4]; title: ; notranslate">
$token&quot;=&#039;xxxxxxxxxxx&#039; 
$headers = @{
 &#039;Content-Type&#039;=&#039;application/json&#039;
 &#039;Authorization&#039;= &#039;Basic $token&#039;
 }

</pre></div>


<p></p>



<p>Once you add the required secured header, you simply call API using the below way,</p>



<p></p>



<p><strong>Example</strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">Invoke-RestMethod -Method 'Post' -Uri $url -Body ($body|ConvertTo-Json) -Headers $headers</pre>



<p></p>



<p><strong><em>References : </em></strong></p>



<p></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/invoke-webrequest-vs-invoke-restmethod-differences/" target="_blank" rel="noreferrer noopener" title="Differences Invoke-WebRequest Vs Invoke-RestMethod"><strong><em>Differences Invoke-WebRequest Vs Invoke-RestMethod</em></strong></a></li>
</ul>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p><p>The post <a href="https://thecodebuzz.com/invoke-restmethod-get-post-example-with-parameters/">Powershell Invoke-RestMethod GET and POST Example</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/invoke-restmethod-get-post-example-with-parameters/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
