title: Encapsulate the output of invoke command in a variable - PowerShell
body: <p>I have a script that installs Remote Desktop Services on remote machines (from the DC).</p>
  
  <p>I'm now at the phase where I check if RDS installed on the connection broker (server) and connection host (server). </p>
  
  <p>I want to use invoke-command since a remote powershell session seemed too complicated. </p>
  
  <p>This is the code I have: </p>
  
  <pre><code>$res = Invoke-Command -ComputerName "testpc.eil.local" -ScriptBlock {
  if((Get-WindowsFeature -Name "Remote-Desktop-Services").Installed -eq 1)
  {
     #i need this output (true or false or a string)
  }
  else
  {
       #i need this output (true or false or a string)
  }
  }
  
  
  Write-Host $res
  </code></pre>
  
  <p>But my question is, how do I encapsulate the output of the scriptblock in the invoke-command in a variable that the DC can access? I'm trying to write away if RDS is succesfully installed or failed to a log-file </p>
  
  <p>How do we encapsulate the output of the function and pass it to the machine who's running it? </p>
  
  <p>Thanks</p>