#requires -version 3.0 Function Edit-RecentFile { <# .Synopsis Open selected files for editing in the PowerShell ISE .Description This command will list the most recently modified files in the specified directory. By default the command will list the 25 most recently modified files. Using Out-Gridview as an interface, you can select the files you wish to edit and they will open in the PowerShell ISE. If you are already in the ISE then each file will open in a new tab. This command requires PowerShell v3. .Example PS C:\> edit-recentfile d:\myscripts -last 10 .Example PS C:\> edit-recentfile c:\work\*.txt #> [cmdletbinding()] Param( [Parameter(Position=0)] [ValidateScript({Test-Path $_})] [string]$Path="c:\scripts", [Parameter(Position=1)] [ValidateNotNullorEmpty()] [int]$Last=25, [switch]$Recurse ) Write-Verbose "Getting $last recent files from $path." #get last X number of files from the path and pipe to Out-Gridview $files = Get-ChildItem -Path $Path -file -Recurse:$Recurse | Sort-Object -Property LastWriteTime -Descending | Select-Object -First $Last -Property FullName,LastWriteTime,Length,Extension | Out-GridView -Title "Select one or more files to edit and click OK" -PassThru #if files were selected, open them in the ISE if ($files) { Write-Verbose "Opening`n$($files.fullname | out-string)" #if in the ISE use PSEDIT if ($host.name -match "ISE") { Write-Verbose "Detected the PowerShell ISE" psedit $files.Fullname } else { #otherwise assume we're in the console Write-Verbose "Defaulting to PowerShell console" ise ($files.FullName -join ",") } } #if $files } #close Edit-RecentFile #define an optional alias Set-Alias -Name erf -Value Edit-RecentFile