Created
December 2, 2015 14:57
-
-
Save pierre3/1970611bec1cf1e0b641 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
短い説明 | |
.DESCRIPTION | |
詳しい説明 | |
.EXAMPLE | |
このコマンドレットの使用方法の例 | |
.EXAMPLE | |
このコマンドレットの使用方法の別の例 | |
#> | |
function Start-ProcessEx | |
{ | |
[CmdletBinding()] | |
[Alias("startx")] | |
[OutputType([int])] | |
Param | |
( | |
# パラメーター 1 のヘルプの説明 | |
[Parameter(Mandatory=$true, Position=0)] | |
[string] | |
$Path, | |
# パラメーター 2 のヘルプの説明 | |
[Parameter(Position=1)] | |
[string[]] | |
$ArgumentList | |
) | |
Process | |
{ | |
if(-not(Test-Path $Path)) | |
{ | |
Write-Error -Exception ([System.IO.FileNotFoundException]::new()) | |
return; | |
} | |
if(($null -eq $ArgumentList) -or ($ArgumentList.Count -eq 0)) | |
{ | |
Start-Process -FilePath $Path; | |
}else{ | |
Start-Process -FilePath $Path -ArgumentList $ArgumentList; | |
} | |
$Shell = New-Object -ComObject Shell.Application; | |
$Shell.AddToRecent($Path); | |
} | |
} | |
Register-ArgumentCompleter -CommandName Start-ProcessEx -ParameterName Path -ScriptBlock { | |
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) | |
$recentFolder = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Recent); | |
$items = Get-ChildItem $recentFolder | Where-Object -Property Extension -EQ ".lnk" | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 20; | |
$wsh = new-object -comobject WScript.Shell | |
foreach($item in $items) | |
{ | |
try | |
{ | |
$shortcut = $Wsh.CreateShortcut($item.FullName); | |
$target = $shortcut.TargetPath; | |
$displayName = Split-Path $target -Leaf; | |
if(Test-Path $target -PathType Container) | |
{ | |
$type = [System.Management.Automation.CompletionResultType]::ProviderContainer; | |
} | |
else | |
{ | |
$type=[System.Management.Automation.CompletionResultType]::ProviderItem; | |
} | |
[System.Management.Automation.CompletionResult]::new($target,$displayName,$type,$target); | |
}catch{ } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment