# Jeffery Hicks # http://jdhitsolutions.com/blog # follow on Twitter: http://twitter.com/JeffHicks # "Those who forget to script are doomed to repeat their work." # **************************************************************** # * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED * # * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK. IF * # * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, * # * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING. * # **************************************************************** Function Get-NumberedContent { param ([string] $filename=$profile) If (Test-Path $filename) { $counter = 0 get-content $filename | foreach { $counter++ #default font color $fcolor="White" #determine if file is a script if ((Get-Item $filename).extension -match "bat|vbs|cmd|wsf|ps1") { #determine if line is a comment. If so we want to write it in Green if ($_.Trim().StartsWith("#") -or ` $_.Trim().StartsWith("'") -or ` $_.Trim().StartsWith("::") -or ` $_.Trim().ToLower().StartsWith("rem")) { $fcolor="Green" } } #write a 4 digit line number the | bar an.d then the line of text from the file #trimming off any trailing spaces Write-Host ("{0:d4} | {1}" -f $counter,$_.TrimEnd()) -foregroundcolor $fcolor } } else { Write-Warning "Failed to find $filename" } } #end function Set-Alias gnc Get-NumberedContent