{"id":86405,"date":"2018-07-24T00:13:07","date_gmt":"2018-07-24T08:13:07","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/koryt\/?p=655"},"modified":"2019-10-09T09:02:34","modified_gmt":"2019-10-09T17:02:34","slug":"powershell-powertip-what-is-the-point-of-out-variable","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powershell-powertip-what-is-the-point-of-out-variable\/","title":{"rendered":"PowerShell PowerTip: What is the point of Out-Variable?"},"content":{"rendered":"<p>A lot of times people see others using the common parameter -OutVariable\u00a0instead of the best practice $var = &lt;value&gt;. This leads to a lot of folks wondering why OutVariable\u00a0 exists.<\/p>\n<p>The real use for OutVariable is to save your data off, while still letting it get sent along the output stream. What this means is that you could use it somewhere inside of a pipe to save some data for later re-use, but continue doing other work with that data.<\/p>\n<pre class=\"lang:ps decode:true \">\r\n\r\nget-process | where {$_.handles -lt 100} -OutVariable LowHandles | foreach {\"$($_.name) is using $($_.handles) handles\"}\r\n$LowHandles.count\r\n\r\n<\/pre>\n<pre class=\"lang:default decode:true \">\r\n\r\nfontdrvhost is using 44 handles\r\nfontdrvhost is using 44 handles\r\nIdle is using 0 handles\r\nLsaIso is using 38 handles\r\nMemory Compression is using 0 handles\r\nRegistry is using 0 handles\r\nSecure System is using 0 handles\r\nSgrmBroker is using 56 handles\r\nsmss is using 52 handles\r\nsvchost is using 84 handles\r\nsvchost is using 98 handles\r\nvmnetdhcp is using 78 handles\r\n\r\n12\r\n\r\n<\/pre>\n<p>Notice that even though the data continued being pipped along, I could also reference it later when I asked for the count.<\/p>\n<p>Hope that helps, tune in more often to get short and sweet PowerTips!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A lot of times people see others using the common parameter -OutVariable\u00a0instead of the best practice $var = &lt;value&gt;. This leads to a lot of folks wondering why OutVariable\u00a0 exists. The real use for OutVariable is to save your data off, while still letting it get sent along the output stream. What this means is [&hellip;]<\/p>\n","protected":false},"author":7300,"featured_media":87096,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1738],"tags":[2221,2125,377,356],"class_list":["post-86405","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-kory-thacher","tag-koryt","tag-powershell","tag-powertip"],"acf":[],"blog_post_summary":"<p>A lot of times people see others using the common parameter -OutVariable\u00a0instead of the best practice $var = &lt;value&gt;. This leads to a lot of folks wondering why OutVariable\u00a0 exists. The real use for OutVariable is to save your data off, while still letting it get sent along the output stream. What this means is [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/86405","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\/7300"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=86405"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/86405\/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=86405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=86405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=86405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}