{"id":7556,"date":"2022-12-08T15:32:50","date_gmt":"2022-12-08T13:32:50","guid":{"rendered":"https:\/\/lazyadmin.nl\/?p=7556"},"modified":"2022-12-08T15:32:52","modified_gmt":"2022-12-08T13:32:52","slug":"concatenate-string","status":"publish","type":"post","link":"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/","title":{"rendered":"How to Concatenate a String in PowerShell"},"content":{"rendered":"\n<p>When outputting data from PowerShell you often need to concatenate two or more strings or variables. Joining strings in PowerShell is primarily done using the <code>+<\/code> operator. But there are other ways to concatenate strings as well.<\/p>\n\n\n\n<p>The problem with joining strings or variables in PowerShell is often finding the correct output method. You might get need extra space between the two strings, or you get the + sign in the output, which you don&#8217;t want of course.<\/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-69f3f53a22bbd\" 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-69f3f53a22bbd\"  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\/concatenate-string\/#powershell-concatenate-string\" >Powershell Concatenate String<\/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\/concatenate-string\/#using-the-join-operator\" >Using the Join Operator<\/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\/concatenate-string\/#using-the-format-operator\" >Using the Format Operator<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#concatenate-string-with-variable\" >Concatenate String with Variable<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#using-the-concat-method\" >Using the Concat Method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#wrapping-up\" >Wrapping Up<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n\n<p>In this article, we will look at the different methods to join multiple strings in PowerShell.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"powershell-concatenate-string\"><\/span>Powershell Concatenate String<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The basic method to concatenate a string in PowerShell is to use the <code>+<\/code> operator. When using the <code>+<\/code> operator, the two strings will simply be joined together. Let&#8217;s take the following two strings to start with:<\/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=\"\">$string1 = \"The quick brown fox\"\n$string2 = \"jumps over the lazy dog\"<\/pre>\n\n\n\n<p>Now if we want to output these strings together in the PowerShell console, people often tend to do the following:<\/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 $string1 + $string2\n\n# Result\nThe quick brown fox + jumps over the lazy dog<\/pre>\n\n\n\n<p>But if you look at the result, you will see that the + sign is also in the output, which we don&#8217;t want. The correct way to output both strings to the console is by simply placing them after each other. <\/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 $string1 $string2\n\n# Result\nThe quick brown fox jumps over the lazy dog<\/pre>\n\n\n\n<p>But this is not concatenating strings. To actually join the strings together we can store the result first in another variable using the <code>+<\/code> operator:<\/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=\"\">$string1 = \"The quick brown fox\"\n$string2 = \"jumps over the lazy dog\"\n\n$result = $string1 + $string2\n\nWrite-Host $result\n\n# Result\nThe quick brown foxjumps over the lazy dog<\/pre>\n\n\n\n<p>The only issue here is that you miss the space between the two strings. So to solve that you could concatenate also a space between the two strings:<\/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=\"\">$result = $string1 + \" \" + $string2<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"using-the-join-operator\"><\/span>Using the Join Operator<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Another method to join strings in PowerShell is to use the Join Operator. The <code>join<\/code> operators allow you to concatenate two or more strings with a specified separator. Taking our two example strings, we can do the following:<\/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=\"\">$result = $string1,$string2 -join \" \"\n\n# Result\nThe quick brown fox jumps over the lazy dog<\/pre>\n\n\n\n<p>Another option is to use the .Net join method. The principal and results are the same as the join operator, only the writing style is a bit different:<\/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=\"\">[string]::Join(' ',$string1,$string2)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"using-the-format-operator\"><\/span>Using the Format Operator<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>When you need to insert multiple variables into a string, then using the string format operator might be a good option to use. The advantage of the format operator <code>-f<\/code> is that it is easier to read and format with longer strings or multiple variables.<\/p>\n\n\n\n<p>The format operator uses placeholders to determine where you want to insert a string or variable. The placeholders are numbered upwards from 0 and placed between curly brackets.<\/p>\n\n\n\n<p>Take the example below, we have a <code>PSCusstomObject<\/code> with a couple of strings. We can concatenate these strings in PowerShell into another string using the string format operator. <\/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=\"\">$obj = [PSCustomObject]@{\n  Name = 'Lazy Dog'\n  Action = 'jump over'\n  Item = \"3 fences\"\n}\n\nwrite-host (\"can the {0} really {1} more than {2}\" -f $obj.name, $obj.action, $obj.item)\n\n# Result\ncan the Lazy Dog really jump over more than 3 fences<\/pre>\n\n\n\n<p>You don&#8217;t need to use variables for the right side of the <code>-f<\/code> operator. You can also insert strings or integers directly:<\/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=\"\">$obj = [PSCustomObject]@{\n  Name = 'Lazy Dog'\n  Action = 'jump over'\n  Item = \"fences\"\n}\n\nwrite-host (\"can the {0} really {1} {2} {3} {4}\" -f $obj.name, $obj.action, 'less than', 5, $obj.item)\n\n# Result\ncan the Lazy Dog really jump over less than 5 fences<\/pre>\n\n\n\n<p>If you have an array with strings that you want to concatenate in PowerShell, then you can also use the format operator, without the need of specifying each individual value for the placeholder.<\/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=\"\">$values = @(\n    \"Lazy Dog\"\n    \"Jumps\"\n    \"fences\"\n)\n'Did you know that the {0} {1} 5 {2}?' -f $values\n\n# Result \nDid you know that the Lazy Dog Jumps 5 fences?<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"concatenate-string-with-variable\"><\/span>Concatenate String with Variable<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Concatenating strings with variables, and especially objects or hashtables, is always a bit challenging. If you have a single variable that you would like to insert into a string, then you can simply place the string between double quotes &#8220;, and insert the variable directly:<\/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=\"\">$var = 'fox'\n\nWrite-Host \"The quick brown $var jumps over the lazy dog\"\n\n# Result\nThe quick brown fox jumps over the lazy dog<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"753\" height=\"251\" src=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/image-7.png\" alt=\"powershell concatenate string\" class=\"wp-image-7557\" srcset=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/image-7.png 753w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/image-7-300x100.png 300w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/image-7-400x133.png 400w, https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/image-7-50x17.png 50w\" sizes=\"(max-width: 753px) 100vw, 753px\" \/><figcaption class=\"wp-element-caption\">powershell concatenate string<\/figcaption><\/figure>\n\n\n\n<p>But when you do this with the properties of an object, then it won&#8217;t work. To solve this you will need to use variable substitution, where you place the variable inside <code>$()<\/code>.<\/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=\"\">$obj = [PSCustomObject]@{\n  Name = 'Lazy Dog'\n  Action = 'jump over'\n  Item = \"fences\"\n}\n\nWrite-Host \"The quick brown fox jumps over the $($obj.name)\"\n\n# Result\nThe quick brown fox jumps over the Lazy Dog<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"using-the-concat-method\"><\/span>Using the Concat Method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In PowerShell, we can also use the .Net concat method to concatenate strings. The advantage of the Join operator or method is that you don&#8217;t need to specify a separator, but that also makes the use case a bit limited.<\/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=\"\">$values = @(\n    \"Lazy Dog\"\n    \"Jumps\"\n    \"fences\"\n)\n\n[string]::Concat('Lazy Dog','Jumps','fences')\n# Or when you have an array with values:\n[string]::Concat($values)\n\n# Result for both methods:\nLazy DogJumpsfences<\/pre>\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>There are a lot of ways in PowerShell to concatenate a string, even more than I have described here. Between these methods, there is little difference when it comes to performance for use cases. So the method to use really depends on the situation and writing style.<\/p>\n\n\n\n<p>When you only need to concatenate a couple of strings, then using the + operator is often the preferred way. When you need to join multiple strings or values, then the format operator (placeholder method) is often easier to read.<\/p>\n\n\n\n<p>Also keep in mind that when you want to output object properties, you will need to wrap them into parentheses <code>$()<\/code> and use double-quotes to wrap the string.<\/p>\n\n\n\n<p>I hope this article helped you with joining strings in PowerShell. 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>When outputting data from PowerShell you often need to concatenate two or more strings or variables. Joining strings in PowerShell is primarily done using the + operator. But there are other ways to concatenate strings as well. The problem with &#8230; <a title=\"How to Concatenate a String in PowerShell\" class=\"read-more\" href=\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/\">Read more<span class=\"screen-reader-text\">How to Concatenate a String in PowerShell<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":7560,"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-7556","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 Concatenate a String in PowerShell &#8212; LazyAdmin<\/title>\n<meta name=\"description\" content=\"Learn how to easily concatenate a string, variable, objects and more with PowerShell. All methods explained!\" \/>\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\/concatenate-string\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Concatenate a String in PowerShell &#8212; LazyAdmin\" \/>\n<meta property=\"og:description\" content=\"Learn how to easily concatenate a string, variable, objects and more with PowerShell. All methods explained!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/\" \/>\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=\"2022-12-08T13:32:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-12-08T13:32:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.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\/concatenate-string\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/\"},\"author\":{\"name\":\"Rudy Mens\",\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952\"},\"headline\":\"How to Concatenate a String in PowerShell\",\"datePublished\":\"2022-12-08T13:32:50+00:00\",\"dateModified\":\"2022-12-08T13:32:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/\"},\"wordCount\":743,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952\"},\"image\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg\",\"keywords\":[\"Powershell\"],\"articleSection\":[\"PowerShell\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/\",\"url\":\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/\",\"name\":\"How to Concatenate a String in PowerShell &#8212; LazyAdmin\",\"isPartOf\":{\"@id\":\"https:\/\/lazyadmin.nl\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg\",\"datePublished\":\"2022-12-08T13:32:50+00:00\",\"dateModified\":\"2022-12-08T13:32:52+00:00\",\"description\":\"Learn how to easily concatenate a string, variable, objects and more with PowerShell. All methods explained!\",\"breadcrumb\":{\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#primaryimage\",\"url\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg\",\"contentUrl\":\"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg\",\"width\":800,\"height\":450},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/lazyadmin.nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Concatenate a String in PowerShell\"}]},{\"@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 Concatenate a String in PowerShell &#8212; LazyAdmin","description":"Learn how to easily concatenate a string, variable, objects and more with PowerShell. All methods explained!","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\/concatenate-string\/","og_locale":"en_US","og_type":"article","og_title":"How to Concatenate a String in PowerShell &#8212; LazyAdmin","og_description":"Learn how to easily concatenate a string, variable, objects and more with PowerShell. All methods explained!","og_url":"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/","og_site_name":"LazyAdmin","article_publisher":"https:\/\/www.facebook.com\/lazyadminnl\/","article_author":"https:\/\/www.facebook.com\/lazyadminnl\/","article_published_time":"2022-12-08T13:32:50+00:00","article_modified_time":"2022-12-08T13:32:52+00:00","og_image":[{"width":800,"height":450,"url":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.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\/concatenate-string\/#article","isPartOf":{"@id":"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/"},"author":{"name":"Rudy Mens","@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952"},"headline":"How to Concatenate a String in PowerShell","datePublished":"2022-12-08T13:32:50+00:00","dateModified":"2022-12-08T13:32:52+00:00","mainEntityOfPage":{"@id":"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/"},"wordCount":743,"commentCount":2,"publisher":{"@id":"https:\/\/lazyadmin.nl\/#\/schema\/person\/cbfba61543b21fbba63cfbf62f08d952"},"image":{"@id":"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#primaryimage"},"thumbnailUrl":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg","keywords":["Powershell"],"articleSection":["PowerShell"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/","url":"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/","name":"How to Concatenate a String in PowerShell &#8212; LazyAdmin","isPartOf":{"@id":"https:\/\/lazyadmin.nl\/#website"},"primaryImageOfPage":{"@id":"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#primaryimage"},"image":{"@id":"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#primaryimage"},"thumbnailUrl":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg","datePublished":"2022-12-08T13:32:50+00:00","dateModified":"2022-12-08T13:32:52+00:00","description":"Learn how to easily concatenate a string, variable, objects and more with PowerShell. All methods explained!","breadcrumb":{"@id":"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#primaryimage","url":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg","contentUrl":"https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg","width":800,"height":450},{"@type":"BreadcrumbList","@id":"https:\/\/lazyadmin.nl\/powershell\/concatenate-string\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/lazyadmin.nl\/"},{"@type":"ListItem","position":2,"name":"How to Concatenate a String in PowerShell"}]},{"@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\/2022\/12\/concatenate-strings.jpg",800,450,false],"thumbnail":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings-150x150.jpg",150,150,true],"medium":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings-300x169.jpg",300,169,true],"medium_large":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings-768x432.jpg",768,432,true],"large":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg",800,450,false],"1536x1536":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg",800,450,false],"2048x2048":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg",800,450,false],"post-thumb":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg",800,450,false],"post-thumb-half":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings-400x225.jpg",400,225,true],"wppr-widget":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings-50x28.jpg",50,28,true],"gform-image-choice-sm":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg",300,169,false],"gform-image-choice-md":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg",400,225,false],"gform-image-choice-lg":["https:\/\/lazyadmin.nl\/wp-content\/uploads\/2022\/12\/concatenate-strings.jpg",600,338,false]},"uagb_author_info":{"display_name":"Rudy Mens","author_link":"https:\/\/lazyadmin.nl\/author\/lajcud8123b\/"},"uagb_comment_info":2,"uagb_excerpt":"When outputting data from PowerShell you often need to concatenate two or more strings or variables. Joining strings in PowerShell is primarily done using the + operator. But there are other ways to concatenate strings as well. The problem with ... Read moreHow to Concatenate a String in PowerShell","_links":{"self":[{"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/posts\/7556"}],"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=7556"}],"version-history":[{"count":0,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/posts\/7556\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/media\/7560"}],"wp:attachment":[{"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/media?parent=7556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/categories?post=7556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lazyadmin.nl\/wp-json\/wp\/v2\/tags?post=7556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}