{"id":8677,"date":"2023-07-17T13:36:50","date_gmt":"2023-07-17T11:36:50","guid":{"rendered":"https:\/\/lazyadmin.nl\/?p=8677"},"modified":"2024-02-29T12:57:12","modified_gmt":"2024-02-29T10:57:12","slug":"powershell-write-host","status":"publish","type":"post","link":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/","title":{"rendered":"How to use Powershell Write Host"},"content":{"rendered":"\n<p>The PowerShell Write-Host cmdlet is used to output text to the console for the user. It&#8217;s commonly used to show the progress of a script, output results, or show instructions for the user.<\/p>\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">In this article<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69f46064bd12e\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\" style='display:none' id=\"ez-toc-cssicon-toggle-item-69f46064bd12e\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#powershell-write-host-cmdlet\" >PowerShell Write-Host CmdLet<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#using-colors-in-write-host\" >Using Colors in Write-Host<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#formatting-the-output\" >Formatting the Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#using-variables-inside-write-host\" >Using Variables inside Write Host<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#using-a-separator\" >Using a Separator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#write-host-formatting-examples\" >Write Host Formatting Examples<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#wrapping-up\" >Wrapping Up<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n\n<p> In this article, we are going to take a look at how to use the Write-Host cmdlet, the different options that it comes with, and I will show you a couple of examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"powershell-write-host-cmdlet\"><\/span>PowerShell Write-Host CmdLet<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The <code>Write-Host<\/code> cmdlet is actually a wrapper for the older Write-Information cmdlet. Until PowerShell 5.0 we had to use the <code>Write-Information<\/code> or <code>Write-Output<\/code> cmdlet to output information to the console. The old cmdlets didn&#8217;t come with a lot of features, whereas write-host gives us a couple of styling options that we can use:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">Parameter<\/th><th class=\"has-text-align-left\" data-align=\"left\">Description<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\">-ForegroundColor<\/td><td class=\"has-text-align-left\" data-align=\"left\">Color of the text<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">-BackgroundColor<\/td><td class=\"has-text-align-left\" data-align=\"left\">Background color of the text<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">-NoNewline<\/td><td class=\"has-text-align-left\" data-align=\"left\">Won&#8217;t add a newline after the output<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">-Separator<\/td><td class=\"has-text-align-left\" data-align=\"left\">Adds a separator between the output of each item in an objects or array<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Write-Host CmdLet Parameters<\/figcaption><\/figure>\n\n\n\n<p>By default, the <code>Write-Host<\/code> cmdlet will output a string on a new line in the console, using the default color of the console (most of the time white):<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Write-Host \"Welcome to the Lazy Script!\"<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" width=\"774\" height=\"236\" src=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-25.png\" alt=\"powershell write host\" class=\"wp-image-8679\" style=\"width:774px;height:236px\" srcset=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-25.png 774w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-25-300x91.png 300w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-25-768x234.png 768w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-25-400x122.png 400w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-25-50x15.png 50w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"using-colors-in-write-host\"><\/span>Using Colors in Write-Host<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Colors are a great way to attract the user&#8217;s attention or tell something about the status non-verbally. For example, yellow text often indicates a warning whereas red text is mostly likely an error. In PowerShell we can assign a color for the text, using the <code>-foregroundcolor<\/code> parameter and a background color for the text with <code>-backgroundcolor<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"774\" height=\"221\" src=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-26.png\" alt=\"write host\" class=\"wp-image-8680\" srcset=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-26.png 774w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-26-300x86.png 300w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-26-768x219.png 768w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-26-400x114.png 400w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-26-50x14.png 50w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/figure>\n\n\n\n<p>We can use the following colors for both parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Black<\/li>\n\n\n\n<li>DarkBlue<\/li>\n\n\n\n<li>DarkGreen<\/li>\n\n\n\n<li>DarkCyan<\/li>\n\n\n\n<li>DarkRed<\/li>\n\n\n\n<li>DarkMagenta<\/li>\n\n\n\n<li>DarkYellow<\/li>\n\n\n\n<li>Gray<\/li>\n\n\n\n<li>DarkGray<\/li>\n\n\n\n<li>Blue<\/li>\n\n\n\n<li>Green<\/li>\n\n\n\n<li>Cyan<\/li>\n\n\n\n<li>Red<\/li>\n\n\n\n<li>Magenta<\/li>\n\n\n\n<li>Yellow<\/li>\n\n\n\n<li>White<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"formatting-the-output\"><\/span>Formatting the Output<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>By default, each string that is outputted by Write-Host is displayed on a new line. In most cases this is fine, but sometimes you don&#8217;t want a new line, or maybe an extra new line between the outputs.<\/p>\n\n\n\n<p>Let&#8217;s first take a look at how to append the results behind the previous Write-Host output. To do this we can use the <code>-NoNewline<\/code> parameter. When added, the next output will append to the existing line:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Write-Host \"Number of mailboxes: \" -NoNewline\n\n# Get all mailboxes function\n$mailboxes = Get-AllMailboxes\n\nWrite-Host $mailboxes\n\n# Result:\nNumber of mailboxes: 5<\/pre>\n\n\n\n<p>As you can see, the value <code>$mailboxes<\/code> is appended behind the line &#8220;Number of mailboxes&#8221;.<\/p>\n\n\n\n<p>If you want to create an extra new blank line between the outputs, then we can use the <code>`n<\/code> character. This will add an extra new line behind the output of the <code>write-host<\/code> cmdlet:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Write-Host \"Getting all user mailboxes `n\" -ForegroundColor Cyan\nWrite-Host \"Shared mailboxes found `n `n\" -ForegroundColor Yellow\nWrite-Host \"Script finished\" -ForegroundColor Green<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"774\" height=\"221\" src=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-27.png\" alt=\"powershell new line write host\" class=\"wp-image-8681\" srcset=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-27.png 774w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-27-300x86.png 300w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-27-768x219.png 768w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-27-400x114.png 400w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-27-50x14.png 50w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"using-variables-inside-write-host\"><\/span>Using Variables inside Write Host<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Good to know is that we can use variables inside the output of the write-host cmdlet. A simple string variable can be included in the string of write-host when using the double-quotes <code>\" \"<\/code>. Keep in mind that you can&#8217;t use variables inside strings wrapped with single-quotes <code>' '<\/code>. The difference here is that PowerShell only processes strings that are wrapped in double quotes.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$user = \"megan@lazyadmin.nl\"\nWrite-Host \"Getting mailbox of $user\"\n\n# Result\nGetting mailbox of megan@lazyadmin.nl<\/pre>\n\n\n\n<p>But when working with objects, you might have noticed that you can&#8217;t output the items of an object. For example, this <strong>won&#8217;t<\/strong> work:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$user = [PSCustomObject]@{\n    DisplayName = \"Megan\"\n    Email = \"megan@lazyadmin.nl\"\n}\n\nWrite-Host \"Getting mailbox of $user.displayname\"<\/pre>\n\n\n\n<p>To show the display name of the user object, we will need to wrap it in parentheses, like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$user = [PSCustomObject]@{\n    DisplayName = \"Megan\"\n    Email = \"megan@lazyadmin.nl\"\n}\n\nWrite-Host \"Getting mailbox of $($user.DisplayName)\"\n\n# Result\nGetting mailbox of Megan<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"using-a-separator\"><\/span>Using a Separator<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>When you want to output the results of an array to the console, then the results will be displayed on a single row by default. For example, I have a CSV file with some fruits. When we import the CSV file and output the result then it will be formatted like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$example = import-csv -path C:\\temp\\example.csv -Header Fruit\nWrite-Host $example.fruit\n\n# Result\nApple Banana Pear Kiwi Raspberry Melon<\/pre>\n\n\n\n<p>To show each fruit on its own line or separate each fruit with a character, we can use the <code>-Separator<\/code> parameter:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Show results on a new line\n$example = import-csv -path C:\\temp\\example.csv -Header Fruit\nWrite-Host $example.fruit -Separator \"`n\"\n\n# Result\nApple\nBanana\nPear\nKiwi\nRaspberry\nMelon\n\n# Separate results with a space and dash\n$example = import-csv -path C:\\temp\\example.csv -Header Fruit\nWrite-Host $example.fruit -Separator \" - \"\n\n# Result\nApple - Banana - Pear - Kiwi - Raspberry - Melon<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"write-host-formatting-examples\"><\/span>Write Host Formatting Examples<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>With some creativity, you can create different banners, or alerts in your scripts that really stand out. Below I gather a couple of examples as inspirations for you. If you have other good examples, please share them in the comments below!<\/p>\n\n\n\n<p>Adding a new line above and below a warning message, adding some space around the message, and using a background color can really make a message stand out:<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Write-Host \"`n\"\nWrite-Host \"   RUNNING IN TEST MODE   \"  -BackgroundColor Yellow -ForegroundColor Black\nWrite-Host \"`n\"<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"795\" height=\"191\" src=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-30.png\" alt=\"powershell write-host cmdlet\" class=\"wp-image-8684\" srcset=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-30.png 795w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-30-300x72.png 300w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-30-768x185.png 768w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-30-400x96.png 400w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-30-50x12.png 50w\" sizes=\"(max-width: 795px) 100vw, 795px\" \/><\/figure>\n<\/div><\/div>\n\n\n\n<p>Script banners are always a bit of a puzzle to get right. In the code example below it doesn&#8217;t look aligned, but when using it in a script you will see a perfect banner.<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Write-Host \"`n\"\nWrite-Host \"                    -------------------------------------------------            \" -ForegroundColor Cyan\nWrite-Host \"                    |                                               |\t\t\t\t\t\t\" -ForegroundColor Cyan\nWrite-Host \"                    |               Create new AD User              |\t\t\t\t\t\t\" -ForegroundColor Cyan\nWrite-Host \"                    |                  Version 1.7                  |\t\t\t\t\t\t\" -ForegroundColor Cyan\nWrite-Host \"                    |                                               |\t\t\t\t\t\t\" -ForegroundColor Cyan\nWrite-Host \"                    |          Author R. Mens - LazyAdmin.nl        |\t\t\t\t\t\t\" -ForegroundColor Cyan\nWrite-Host \"                    |                                               |\t\t\t\t\t\t\" -ForegroundColor Cyan\nWrite-Host \"                    -------------------------------------------------            \" -ForegroundColor Cyan\nWrite-Host \"`n\"<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"795\" height=\"266\" src=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-31.png\" alt=\"create banner in PowerShell\" class=\"wp-image-8685\" srcset=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-31.png 795w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-31-300x100.png 300w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-31-768x257.png 768w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-31-400x134.png 400w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-31-50x17.png 50w\" sizes=\"(max-width: 795px) 100vw, 795px\" \/><\/figure>\n<\/div><\/div>\n\n\n\n<p>We can also do something fun with the foreground colors and some ASCII art. The code below divides the position of each character with 6. Depending on the result, it will assign a color to the character. By using the <code>-NoNewline<\/code> parameter we can append the results:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$text = \"\n _                      ___      _           _       \n| |                    \/ _ \\    | |         (_)      \n| |     __ _ _____   _\/ \/_\\ \\ __| |_ __ ___  _ _ __  \n| |    \/ _  |_  \/ | | |  _  |\/ _  | '_   _ \\| | '_ \\ \n| |___| (_| |\/ \/| |_| | | | | (_| | | | | | | | | | |\n\\_____\/\\__,_\/___|\\__, \\_| |_\/\\__,_|_| |_| |_|_|_| |_|\n                  __\/ |                              \n                 |___\/                               \"\n\n\nfor ($i=0; $i -lt $text.length; $i++) {\n    switch ($i % 6) {\n        0 { $c = \"white\" }\n        2 { $c = \"green\" }\n        4 { $c = \"blue\" }\n        default { $c = \"cyan\" }\n    }\nwrite-host $text[$i] -NoNewline -ForegroundColor $c\n}<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"795\" height=\"266\" src=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-32.png\" alt=\"PowerShell ASCII art with colors\" class=\"wp-image-8686\" srcset=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-32.png 795w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-32-300x100.png 300w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-32-768x257.png 768w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-32-400x134.png 400w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/image-32-50x17.png 50w\" sizes=\"(max-width: 795px) 100vw, 795px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"wrapping-up\"><\/span>Wrapping Up<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The Write-Host cmdlet is a great way to keep the user of your script informed about the progress of your scripts. It can give instructions to the user, show the results, or simply inform the user when the script is completed or runs into an error.<\/p>\n\n\n\n<p>Make good use of the foreground colors, because they really help with quickly identifying the meaning of a message.<\/p>\n\n\n\n<p>I hope you like this article, if you have any questions, just drop a comment below!<\/p>\n<script async src=\"https:\/\/alatus.eocampaign1.com\/form\/d0ce5de8-9b48-11ee-8cf4-eb425eea7369.js\" data-form=\"d0ce5de8-9b48-11ee-8cf4-eb425eea7369\"><\/script>","protected":false},"excerpt":{"rendered":"<p>The PowerShell Write-Host cmdlet is used to output text to the console for the user. It&#8217;s commonly used to show the progress of a script, output results, or show instructions for the user. In this article, we are going to &#8230; <a title=\"How to use Powershell Write Host\" class=\"read-more\" href=\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/\">Read more<span class=\"screen-reader-text\">How to use Powershell Write Host<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":8689,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[69],"tags":[22],"class_list":["post-8677","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-powershell"],"wppr_data":{"cwp_meta_box_check":"No"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to use Powershell Write Host &#8212; LazyAdmin<\/title>\n<meta name=\"description\" content=\"Format your console output with the PowerShell Write-Host cmdlet. Including examples to style the output of your scripts.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to use Powershell Write Host &#8212; LazyAdmin\" \/>\n<meta property=\"og:description\" content=\"Format your console output with the PowerShell Write-Host cmdlet. Including examples to style the output of your scripts.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/\" \/>\n<meta property=\"og:site_name\" content=\"LazyAdmin\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/lazyadminnl\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/lazyadminnl\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-17T11:36:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-29T10:57:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"450\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Rudy Mens\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/lazyadmin\" \/>\n<meta name=\"twitter:site\" content=\"@lazyadmin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rudy Mens\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/\"},\"author\":{\"name\":\"Rudy Mens\",\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952\"},\"headline\":\"How to use Powershell Write Host\",\"datePublished\":\"2023-07-17T11:36:50+00:00\",\"dateModified\":\"2024-02-29T10:57:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/\"},\"wordCount\":823,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952\"},\"image\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg\",\"keywords\":[\"Powershell\"],\"articleSection\":[\"PowerShell\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/\",\"url\":\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/\",\"name\":\"How to use Powershell Write Host &#8212; LazyAdmin\",\"isPartOf\":{\"@id\":\"https:\/\/lazyadmin.nl\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg\",\"datePublished\":\"2023-07-17T11:36:50+00:00\",\"dateModified\":\"2024-02-29T10:57:12+00:00\",\"description\":\"Format your console output with the PowerShell Write-Host cmdlet. Including examples to style the output of your scripts.\",\"breadcrumb\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#primaryimage\",\"url\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg\",\"contentUrl\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg\",\"width\":800,\"height\":450},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/lazyadmin.nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to use Powershell Write Host\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/lazyadmin.nl\/#website\",\"url\":\"https:\/\/lazyadmin.nl\/\",\"name\":\"LazyAdmin\",\"description\":\"Tips and howto&#039;s about Office 365, PowerShell, Home network and smart devices\",\"publisher\":{\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/lazyadmin.nl\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952\",\"name\":\"Rudy Mens\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/06\/Profile-photo-2024-Ruud.jpg\",\"contentUrl\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/06\/Profile-photo-2024-Ruud.jpg\",\"width\":500,\"height\":500,\"caption\":\"Rudy Mens\"},\"logo\":{\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/image\/\"},\"description\":\"Ruud worked for more than 15 years as a SysAdmin in the Netherlands and is now working as an independent consultant. In his spare time, he loves to thinker with Smart Devices.\",\"sameAs\":[\"https:\/\/lazyadmin.nl\",\"https:\/\/www.facebook.com\/lazyadminnl\/\",\"http:\/\/nl.linkedin.com\/in\/rudymens\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/lazyadmin\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to use Powershell Write Host &#8212; LazyAdmin","description":"Format your console output with the PowerShell Write-Host cmdlet. Including examples to style the output of your scripts.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/","og_locale":"en_US","og_type":"article","og_title":"How to use Powershell Write Host &#8212; LazyAdmin","og_description":"Format your console output with the PowerShell Write-Host cmdlet. Including examples to style the output of your scripts.","og_url":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/","og_site_name":"LazyAdmin","article_publisher":"https:\/\/www.facebook.com\/lazyadminnl\/","article_author":"https:\/\/www.facebook.com\/lazyadminnl\/","article_published_time":"2023-07-17T11:36:50+00:00","article_modified_time":"2024-02-29T10:57:12+00:00","og_image":[{"width":800,"height":450,"url":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg","type":"image\/jpeg"}],"author":"Rudy Mens","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/lazyadmin","twitter_site":"@lazyadmin","twitter_misc":{"Written by":"Rudy Mens","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#article","isPartOf":{"@id":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/"},"author":{"name":"Rudy Mens","@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952"},"headline":"How to use Powershell Write Host","datePublished":"2023-07-17T11:36:50+00:00","dateModified":"2024-02-29T10:57:12+00:00","mainEntityOfPage":{"@id":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/"},"wordCount":823,"commentCount":2,"publisher":{"@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952"},"image":{"@id":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#primaryimage"},"thumbnailUrl":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg","keywords":["Powershell"],"articleSection":["PowerShell"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/","url":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/","name":"How to use Powershell Write Host &#8212; LazyAdmin","isPartOf":{"@id":"https:\/\/lazyadmin.nl\/#website"},"primaryImageOfPage":{"@id":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#primaryimage"},"image":{"@id":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#primaryimage"},"thumbnailUrl":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg","datePublished":"2023-07-17T11:36:50+00:00","dateModified":"2024-02-29T10:57:12+00:00","description":"Format your console output with the PowerShell Write-Host cmdlet. Including examples to style the output of your scripts.","breadcrumb":{"@id":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#primaryimage","url":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg","contentUrl":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg","width":800,"height":450},{"@type":"BreadcrumbList","@id":"https:\/\/lazyadmin.nl\/powershell\/powershell-write-host\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/lazyadmin.nl\/"},{"@type":"ListItem","position":2,"name":"How to use Powershell Write Host"}]},{"@type":"WebSite","@id":"https:\/\/lazyadmin.nl\/#website","url":"https:\/\/lazyadmin.nl\/","name":"LazyAdmin","description":"Tips and howto&#039;s about Office 365, PowerShell, Home network and smart devices","publisher":{"@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/lazyadmin.nl\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952","name":"Rudy Mens","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/image\/","url":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/06\/Profile-photo-2024-Ruud.jpg","contentUrl":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2024\/06\/Profile-photo-2024-Ruud.jpg","width":500,"height":500,"caption":"Rudy Mens"},"logo":{"@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/image\/"},"description":"Ruud worked for more than 15 years as a SysAdmin in the Netherlands and is now working as an independent consultant. In his spare time, he loves to thinker with Smart Devices.","sameAs":["https:\/\/lazyadmin.nl","https:\/\/www.facebook.com\/lazyadminnl\/","http:\/\/nl.linkedin.com\/in\/rudymens\/","https:\/\/x.com\/https:\/\/twitter.com\/lazyadmin"]}]}},"uagb_featured_image_src":{"full":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg",800,450,false],"thumbnail":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host-150x150.jpg",150,150,true],"medium":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host-300x169.jpg",300,169,true],"medium_large":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host-768x432.jpg",768,432,true],"large":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg",800,450,false],"1536x1536":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg",800,450,false],"2048x2048":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg",800,450,false],"post-thumb":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg",800,450,false],"post-thumb-half":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host-400x225.jpg",400,225,true],"wppr-widget":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host-50x28.jpg",50,28,true],"gform-image-choice-sm":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg",300,169,false],"gform-image-choice-md":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg",400,225,false],"gform-image-choice-lg":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2023\/07\/PowerShell-Write-Host.jpg",600,338,false]},"uagb_author_info":{"display_name":"Rudy Mens","author_link":"https:\/\/lazyadmin.nl\/author\/lajcud8123b\/"},"uagb_comment_info":2,"uagb_excerpt":"The PowerShell Write-Host cmdlet is used to output text to the console for the user. It&#8217;s commonly used to show the progress of a script, output results, or show instructions for the user. In this article, we are going to ... Read moreHow to use Powershell Write Host","_links":{"self":[{"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/posts\/8677"}],"collection":[{"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/comments?post=8677"}],"version-history":[{"count":0,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/posts\/8677\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/media\/8689"}],"wp:attachment":[{"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/media?parent=8677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/categories?post=8677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/tags?post=8677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}