Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- New-Alias which get-command
- "`nNew-Alias which get-command" | add-content $profile
- gcm notepad
- gcm note*
- [27] ยป gcm note*
- CommandType Name Definition
- ----------- ---- ----------
- Application notepad.exe C:WINDOWSnotepad.exe
- Application notepad.exe C:WINDOWSsystem32notepad.exe
- Application Notepad2.exe C:UtilsNotepad2.exe
- Application Notepad2.ini C:UtilsNotepad2.ini
- Function Find-Path($Path, [switch]$All=$false, [Microsoft.PowerShell.Commands.TestPathType]$type="Any")
- ## You could comment out the function stuff and use it as a script instead, with this line:
- # param($Path, [switch]$All=$false, [Microsoft.PowerShell.Commands.TestPathType]$type="Any")
- if($(Test-Path $Path -Type $type)) {
- return $path
- } else {
- [string[]]$paths = @($pwd);
- $paths += "$pwd;$env:path".split(";")
- $paths = Join-Path $paths $(Split-Path $Path -leaf) | ? { Test-Path $_ -Type $type }
- if($paths.Length -gt 0) {
- if($All) {
- return $paths;
- } else {
- return $paths[0]
- }
- }
- }
- throw "Couldn't find a matching path of type $type"
- }
- Set-Alias find Find-Path
- function which([string]$command) {
- begin { $Script:ErrorActionPreference = "SilentlyContinue" }
- process {
- if(!$_) { $_ = $command }
- Microsoft.PowerShell.CoreGet-Command $_ |
- sort {
- if($_.CommandType -match "ExternalScript|Application") {
- 1000 + [array]::IndexOf( (Get-Content Env:Path).Split(";"),
- [IO.Path]::GetDirectoryName($_.Definition) )
- } else {
- [int]$_.CommandType
- }
- } | Select -first 1 # only return the first item
- }
- }
- ($Env:Path).Split(";") | Get-ChildItem -filter notepad
Add Comment
Please, Sign In to add comment