#requires -version 2.0 <# If you have a variable in your session called ScriptPath, this function will automatically use it. Otherwise it will default to the current location. #> Function Get-LatestScript { <# .SYNOPSIS List most recently edited PowerShell files .DESCRIPTION This command will find recently modified PowerShell scripts and display the results using Out-GridView. The command will recursively search in the given folder for *.ps1,*.psd1,*.psm1,*.ps1xml files. It will limit the results to the newest number of files based on the last write time. Output is sent to Out-Gridview. The function will use a global variable you can set in your profile or session called ScriptPath for your script directory. Otherwise it will use the current location. .PARAMETER Path The path to your scripts. The default is a global variable ScriptPath which you can set. Otherwise the function will use the current location. .PARAMETER Newest Limits the number of results based on the last write time property. .EXAMPLE PS C:\> Get-LastestScript Use default settings and display 10 most recent script files in the path specified by $Scriptpath. .EXAMPLE PS C:\> Get-LatestScript C:\work 5 -verbose Get the 5 most recent script files from C:\Work .NOTES NAME : Get-LatestScript VERSION : 0.9 LAST UPDATED: 5/18/2012 AUTHOR : Jeffery Hicks (http://jdhitsolutions.com/blog) .LINK Out-GridView Get-Childitem .INPUTS String .OUTPUTS None #> [cmdletbinding()] Param( [Parameter(Position=0)] [ValidateScript({Test-Path $_})] [string]$Path=$global:ScriptPath, [Parameter(Position=1)] [ValidateScript({$_ -ge 1})] [int]$Newest=10 ) if (-Not $path) { $Path=(Get-Location).Path } #define a list of file extensions $include="*.ps1","*.psd1","*.psm1","*.ps1xml" Write-Verbose ("Getting {0} PowerShell files from {1}" -f $newest,$path) #construct a title for Out-GridView $Title=("Recent PowerShell Files in {0}" -f $path.ToUpper()) Get-ChildItem -Path $Path -Include $include -Recurse | Sort-Object -Property lastWriteTime -Descending | Select-Object -First $newest -Property LastWriteTime,CreationTime, @{Name="Size";Expression={$_.length}}, @{Name="Lines";Expression={(Get-Content $_.Fullname | Measure-object -line).Lines}}, Directory,Name,FullName | Out-Gridview -Title $Title }