如何编写PowerShell别名以更改目录并列出所有文件和文件夹?
我正在尝试编写一个类似于如何编写PowerShell别名以更改目录并列出所有文件和文件夹?,powershell,Powershell,我正在尝试编写一个类似于cs*directory*的命令,它将立即更改目录并列出所有项目。如何使用PowerShell执行此操作?使用函数。例如: function cs { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [String] $path ) Set-Location -LiteralPath $path -ErrorAction Stop Get-ChildItem } cs将是
cs*directory*
的命令,它将立即更改目录并列出所有项目。如何使用PowerShell执行此操作?使用函数。例如:
function cs {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[String] $path
)
Set-Location -LiteralPath $path -ErrorAction Stop
Get-ChildItem
}
cs
将是一个别名,而不是一个函数。您可以将cd
与ls
或gci
!;-)你为什么要为这么琐碎的事情重新发明轮子?