title: How to execute a powershell script, Active Directory, remotely
body: <p>I'm trying to execute a powershell script on a remote computer that has access to the Active Directory Module, and the Invoke-Command -ComputerName ... isn't working right. Do I have any other options? </p>
  
  <p>What I would really like to be able to accomplish is query my AD using the Get-ADComputer and even the Remove-ADComputer.</p>
  
  <p>UPDATE</p>
  
  <p>Ok so This is my script</p>
  
  <pre><code>Import-Module ActiveDirectory
  
  $computer = 'mjdl736'
  
  $filter = "(name="+$computer+")"
  
  Get-ADComputer -LDAPFilter $filter
  </code></pre>
  
  <p>and since on my local machine I don't have access to the ActiveDirectory module I would like to run this code on a computer that do have access. So I tried</p>
  
  <pre><code>Invoke-Command mjdl736 -FilePath 'C:\Test1.ps1'
  </code></pre>
  
  <p>Which mjdl736 does have access to ActiveDirectory and the Test1.ps1 is on my local machine</p>
  
  <p>UPDATE 2</p>
  
  <p>This is the error I get : Error initializing default drive: ‘Unable to find a default server with Active Directory Web Services running</p>
  
  <p>Thank you</p>