title: Run a Powershell command (not script) from Excel VBA
body: <p>I've searched SO, and I can find plenty of examples of running a PowerShell script from VBA, but I can't find any examples of just running a simple command.</p>
  
  <p>For example, this works:</p>
  
  <pre><code>Dim retval As Variant
  retval = Shell("PowerShell ""C:\MyScript.ps1""", vbNormalFocus)
  </code></pre>
  
  <p>But this does not:</p>
  
  <pre><code>Dim retval As Variant
  Dim pscmd As String
  
  pscmd = "PowerShell " &amp; _
    Chr(34) &amp; "Get-ScheduledTask" &amp; _
    " -TaskName " &amp; Chr(34) &amp; "My Task" &amp; Chr(34) &amp; _
    " -CimSession MYLAPTOP" &amp; Chr(34)
  retval = Shell(pscmd, vbNormalFocus)
  
  Debug.Print pscmd
  'pscmd = PowerShell "Get-ScheduledTask -TaskName "My Task" -CimSession MYLAPTOP"
  </code></pre>
  
  <p>I know I could write the PS command to a file, execute it as a script, and then delete the file, but that does not seem to be very elegant.</p>