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

PowerTip: Find How Many Scripts Use Write-Host

$
0
0

Summary: Use Windows PowerShell to find how many scripts use the Write-Host cmdlet.

Hey, Scripting Guy! Question I am trying to improve how I write Windows PowerShell scripts, and I want to reduce the number of times I use 
           Write-Host. How can I find how many times I used this cmdlet in my scripts?

Hey, Scripting Guy! Answer Use the Get-ChildItem cmdlet to retrieve all .ps1 files from your script directory. Then pipe the FileInfo objects
           to the Select-String cmdlet and look for the pattern Write-Host. Use the Quiet switch and pipe the results to
           the Group-Object cmdlet, for example:

gci E:\Data\PSExtras\ -Filter *.ps1 | Select-String -Pattern "write-host" -Quiet | group

Note  gci is an alias for Get-ChildItem, and group is an alias for Group-Object.


Viewing all articles
Browse latest Browse all 3333

Trending Articles



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