Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

PowerTip: Store Current Pipeline Value in Variables with PowerShell

$
0
0

Summary: Use PowerShell to store current pipeline values in variables.

Hey, Scripting Guy! Question How can I use Windows PowerShell to improve my code by storing the current pipeline value into variables?

Hey, Scripting Guy! Answer Use the new PipelineVariable common parameter, for example:

Get-Counter -ListSet 'LogicalDisk','SQLServer:Buffer Manager','SQLServer:Memory Manager' -PipelineVariable CounterCategory | 

Select-Object -ExpandProperty Counter -PipelineVariable CounterName |

Where-Object {$CounterName -match '(sec/Transfer|Avg. Disk Queue Length|Buffer Cache|CheckPoint|Target Server|Total)'} | 

Select-Object   @{E={$CounterCategory.CounterSetName};N="CounterSetName"},

                @{E={$CounterCategory.Description};N="Description"},

                @{E={$CounterName};N="Counter"}

Note  PipelineVariable was introduced in Windows PowerShell 4.0.


Viewing all articles
Browse latest Browse all 3333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>