我使用C:UsersUserDocumentsPowershellMicrosoft.PowerShell_profile.ps1
作为我日常工作的一些别名命令。
的例子:
function MyAliasCommand { .customscript.ps1 }
New-Alias my MyAliasCommand
如果我在Powershell中使用"my"命令调用它,它就会工作。
我很高兴。
它不起作用的是,如果我需要将标志传递给my
,例如:
my -d one
如何做到这一点?
有没有办法让powershell在function MyAliasCommand
中传递我所有的参数?
例如:function MyAliasCommand { .customscript.ps1 $allTheFlags }
?
我将这样做:./custom/script.ps1
[CmdletBinding()]
param (
[Parameter()]
[string]
$d
)
Write-Host $d
那么你可以写:
function MyCommand {
& $PSScriptRoot/custom/script.ps1 @args
}
New-Alias myAlias MyCommand
myAlias -d 'one'
考虑到我使用了调用操作符和溅射。
$args
将包含您提供的所有参数。