{"id":75481,"date":"2015-11-24T11:59:00","date_gmt":"2015-11-24T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/11\/24\/powertip-store-current-pipeline-value-in-variables-with-powershell\/"},"modified":"2019-02-18T09:20:57","modified_gmt":"2019-02-18T16:20:57","slug":"powertip-store-current-pipeline-value-in-variables-with-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-store-current-pipeline-value-in-variables-with-powershell\/","title":{"rendered":"PowerTip: Store Current Pipeline Value in Variables with PowerShell"},"content":{"rendered":"<p><span style=\"font-size:12px\"><strong>Summary<\/strong>: Use PowerShell to store current pipeline values in variables.<\/span><\/p>\n<p><span style=\"font-size:12px\"><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 can I use Windows PowerShell to improve my code by storing the current pipeline value into variables?<\/span><\/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\">&nbsp;Use the new <b>PipelineVariable<\/b> common parameter, for example:<\/p>\n<p>Get-Counter -ListSet &#8216;LogicalDisk&#8217;,&#8217;SQLServer:Buffer Manager&#8217;,&#8217;SQLServer:Memory Manager&#8217; -PipelineVariable CounterCategory |&nbsp;<\/p>\n<p>Select-Object -ExpandProperty Counter -PipelineVariable CounterName |<\/p>\n<p>Where-Object {$CounterName -match &#8216;(sec\/Transfer|Avg. Disk Queue Length|Buffer Cache|CheckPoint|Target Server|Total)&#8217;} |&nbsp;<\/p>\n<p>Select-Object &nbsp; @{E={$CounterCategory.CounterSetName};N=&#8221;CounterSetName&#8221;},<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @{E={$CounterCategory.Description};N=&#8221;Description&#8221;},<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @{E={$CounterName};N=&#8221;Counter&#8221;}<\/p>\n<p style=\"margin-left:30px\"><b>Note<\/b>&nbsp;&nbsp;<b>PipelineVariable<\/b> was introduced in Windows PowerShell&nbsp;4.0.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Use PowerShell to store current pipeline values in variables. &nbsp;How can I use Windows PowerShell to improve my code by storing the current pipeline value into variables? &nbsp;Use the new PipelineVariable common parameter, for example: Get-Counter -ListSet &#8216;LogicalDisk&#8217;,&#8217;SQLServer:Buffer Manager&#8217;,&#8217;SQLServer:Memory Manager&#8217; -PipelineVariable CounterCategory |&nbsp; Select-Object -ExpandProperty Counter -PipelineVariable CounterName | Where-Object {$CounterName -match &#8216;(sec\/Transfer|Avg. Disk [&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":[635,56,350,356,3,45],"class_list":["post-75481","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-automation","tag-guest-blogger","tag-laerte-junior","tag-powertip","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Use PowerShell to store current pipeline values in variables. &nbsp;How can I use Windows PowerShell to improve my code by storing the current pipeline value into variables? &nbsp;Use the new PipelineVariable common parameter, for example: Get-Counter -ListSet &#8216;LogicalDisk&#8217;,&#8217;SQLServer:Buffer Manager&#8217;,&#8217;SQLServer:Memory Manager&#8217; -PipelineVariable CounterCategory |&nbsp; Select-Object -ExpandProperty Counter -PipelineVariable CounterName | Where-Object {$CounterName -match &#8216;(sec\/Transfer|Avg. Disk [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/75481","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=75481"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/75481\/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=75481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=75481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=75481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}