我正在为 PowerShell 创建一个 cmdlet,我需要能够从 cmdlet 中调用Set-Location(aka cd)。我会这样做
var setLocation = new Microsoft.PowerShell.Commands.SetLocationCommand();
setLocation.Path = path;
setLocation.Invoke();
除了它给了我一个错误,上面写着You cannot invoke a cmdlet that derrives from PSCmdlet。我想使用Set-Location,但我很乐意只更改 shell 的目录。