小编Bil*_*ble的帖子

如何在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
查看次数

构造函数链接传递参数的计算值

我怎样才能从一个实例化器传递到另一个实例器?假设我们有这门课.如何从foo(字符串,字符串)传递给foo(Uri)?

public foo
{
   string path { get; private set; }
   string query { get; private set; }

   public foo (Uri someUrl)
   {
      // ... do stuff here
   }

   public foo (string path, string query)
   {
      Uri someUrl = new Uri(String.Concat(path, query);

      // ... do stuff here to pass thru to foo(someUrl)
   }
}
Run Code Online (Sandbox Code Playgroud)

c#

5
推荐指数
2
解决办法
575
查看次数

如何在PowerShell C#cmdlet中使用WriteProgressCommand?

更新.cmdlet在Visual Studio 2010中使用C#/ .Net 4.0 创建了一个PowerShell 3.0 .它工作正常.但cmdlet需要一段时间,我想添加一个进度条.

关于WriteProgressCommand的MSDN文档含糊不清.这是链接:http://msdn.microsoft.com/en-us/library/microsoft.powershell.commands.writeprogresscommand.completed(v=vs.85).aspx

下面的代码显示了我想要做的事情.基本上做一些处理ProcessRecord().然后每秒更新进度条.不确定如何显示进度条.救命?

[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()
    {
        WriteProgressCommand progress = new WriteProgressCommand();

        for (int i = 0; i < 60; i++)
        {
            System.Threading.Thread.Sleep(1000);
            progress.PercentComplete = i;
        }

        progress.Completed = true;
        this.WriteObject("Done.");
        return;
    }
}

// Commented out thanks to Graimer's answer …
Run Code Online (Sandbox Code Playgroud)

c# powershell .net-4.0

4
推荐指数
1
解决办法
2388
查看次数

标签 统计

c# ×3

powershell ×2

.net-4.0 ×1

c#-4.0 ×1