{"id":2002,"date":"2014-02-15T11:59:00","date_gmt":"2014-02-15T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/02\/15\/powertip-include-expressions-in-a-string-in-powershell\/"},"modified":"2014-02-15T11:59:00","modified_gmt":"2014-02-15T11:59:00","slug":"powertip-include-expressions-in-a-string-in-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-include-expressions-in-a-string-in-powershell\/","title":{"rendered":"PowerTip: Include Expressions in a String in PowerShell"},"content":{"rendered":"<p><b>Summary<\/b>: Learn how to include expressions in a string in Windows PowerShell.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;How do I include expressions in a string in Windows PowerShell? They&#8217;re not replaced correctly in a <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double-quoted string:<\/p>\n<p class=\"Code\" style=\"margin-left:90px\">PS C:&gt; $p = Get-Process PowerShell<br \/>PS C:&gt;&#8221;The $p.Name process uses the $p.StartInfo.WindowStyle window style.&#8221;<\/p>\n<p class=\"Code\" style=\"margin-left:90px\">The System.Diagnostics.Process (powershell).Name process uses the <br \/>System.Diagnostics.Process (powershell).StartInfo.WindowStyle window style.<\/p>\n<p style=\"margin-left:30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" width=\"32\" height=\"35\">&nbsp;Enclose the values in a new variable:<\/p>\n<p class=\"Code\" style=\"margin-left:90px\">PS C:&gt;&#8221;The $($p.Name) process uses the $($p.StartInfo.WindowStyle) window style.&#8221;<br \/>The powershell process uses the Normal window style.<\/p>\n<p style=\"margin-left:30px\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Or use a formatted string:<\/p>\n<p class=\"Code\" style=\"margin-left:90px\">PS C:&gt;&#8221;The {0} process uses the {1} window style.&#8221; -f $p.Name, $p.StartInfo.WindowStyle<br \/>The powershell process uses the Normal window style.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to include expressions in a string in Windows PowerShell. &nbsp;How do I include expressions in a string in Windows PowerShell? They&#8217;re not replaced correctly in a &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double-quoted string: PS C:&gt; $p = Get-Process PowerShellPS C:&gt;&#8221;The $p.Name process uses the $p.StartInfo.WindowStyle window style.&#8221; The System.Diagnostics.Process (powershell).Name process uses [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[56,370,3,45],"class_list":["post-2002","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-june-blender","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to include expressions in a string in Windows PowerShell. &nbsp;How do I include expressions in a string in Windows PowerShell? They&#8217;re not replaced correctly in a &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double-quoted string: PS C:&gt; $p = Get-Process PowerShellPS C:&gt;&#8221;The $p.Name process uses the $p.StartInfo.WindowStyle window style.&#8221; The System.Diagnostics.Process (powershell).Name process uses [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=2002"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2002\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=2002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}