Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何编写PowerShell别名以更改目录并列出所有文件和文件夹?_Powershell - Fatal编程技术网

如何编写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
!;-)你为什么要为这么琐碎的事情重新发明轮子?