title: Set Paramerters in ScriptBlock when Executing Powershell Commands with C#
body: <p>I am trying to executing the following powershell command in C#</p>
  
  <pre><code>Invoke-Command -Session $session -ScriptBlock {
    Get-MailboxPermission -Identity ${identity} -User ${user}
  }
  </code></pre>
  
  <p>I tried with following C# code but couldn't set the identity and user parameters.</p>
  
  <pre><code>var command = new PSCommand();
  command.AddCommand("Invoke-Command");
  command.AddParameter("ScriptBlock", ScriptBlock.Create("Get-MailboxPermission -Identity ${identity} -User ${user}"));
  command.AddParameter("identity", mailbox);
  command.AddParameter("user", user);
  </code></pre>
  
  <p>When I hard code the values when creating the ScriptBlock, it's working fine. How can I set the params dynamically.</p>
  
  <p>Is there a better way to do this rather concatenate values as below.</p>
  
  <pre><code>command.AddParameter("ScriptBlock", ScriptBlock.Create("Get-MailboxPermission -Identity " + mailbox + " -User " + user));
  </code></pre>