Monday, January 9, 2012

"More" Can Be Dangerous - Use Better Alternative in PowerShell


PowerTip of the Day, from


You might know the tool: when you pipe output to, the output is displayed page by page:

PS> Get-EventLog -LogName System | more

However, "more" can be dangerous as you see here. You will not get any results for a long time, and your CPU load increases. first collects all results before it starts paginating it. This takes a long time and a lot of resources.

That's why you should avoid and instead use Out-Host with the parameter -Paging.

PS> Get-EventLog -LogName System | Out-Host -Paging

You immediately see the benefit: results appear momentarily, and no additional CPU load is created.

No comments:

Post a Comment