相关疑难解决方法(0)

如何在PowerShell cmdlet中获取当前目录?

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)

c# powershell c#-4.0

8
推荐指数
1
解决办法
3809
查看次数

标签 统计

c# ×1

c#-4.0 ×1

powershell ×1