我正在Visual Studio 2010中使用C#/ .Net 4.0開發PowerShell 3.0 cmdlet
我想在PowerShell中獲取當前目錄,用戶在其中執行cmdlet
。但Directory.GetCurrentDirectory()不能按預期工作。在下面的代碼中,結果是C:\ Users \ Administrator。如何獲取PowerShell cmdlet中的當前目錄?
問題:什麼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;
}
}
$(GET-位置)或$ PWD –