我cmdlet在Visual Studio 2010中使用C#/ .Net 4.0 开发PowerShell 3.0 .我想在PowerShell中获取用户执行的当前目录cmdlet.但Directory.GetCurrentDirectory()无法按预期工作.在下面的代码中,结果是C:\ Users\Administrator.
问题:使用什么cmdlet代码获取PowerShell的当前目录?
[System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.Get, "StatusBar")]
public class GetStatusBarCommand : System.Management.Automation.PSCmdlet
{
/// <summary>
/// Provides a record-by-record processing functionality for the cmdlet.
/// </summary>
protected override void ProcessRecord()
{
this.WriteObject(Directory.GetCurrentDirectory());
return;
}
}
Run Code Online (Sandbox Code Playgroud)