title: Access is Denied when Reset-ComputerMachinePassword is run through Invoke-command
body: <p>I'm using the following command to reset a remote machine'
  s password.</p>
  
  <pre><code>$user="Domain\domainadmin";
  $pass="dapassword" | ConvertTo-SecureString -AsPlainText -Force;
  $creds=New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $pass;
  Invoke-Command -Credential $creds -ComputerName "DomainControllerMachine" -ScriptBlock{ 
  $ComputerName = @"
  SomeRemoteHost
  "@
  Import-Module ActiveDirectory; 
  Reset-ComputerMachinePassword -Server ${ComputerName};
  }
  </code></pre>
  
  <p>I keep getting 'Access is denied' error.</p>
  
  <pre><code>This command cannot be executed on target computer('DomainControllerMachine') due to following error: Access is
   denied.
      + CategoryInfo          : InvalidOperation: (DomainControllerMachine:String) [Reset-ComputerMachinePasswor
     d], InvalidOperationException
      + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.ResetCompute
     rMachinePasswordCommand
  </code></pre>
  
  <p>The account I use has all levels of access to the ActiveDirectory. So there won't be a issue with the credentials used for authentication.</p>
  
  <p>If I run the same command on the 'DomainControllerMachine' (logged in as same user) it works fine.</p>
  
  <pre><code>Import-Module ActiveDirectory; 
  Reset-ComputerMachinePassword -Server "SomeRemoteHost";
  </code></pre>
  
  <p>Even the whole invoke-command block above just works without complaining on the DomainControllerMachine.
  But when I do it remotely through Invoke-Command, or Enter-PSSession I get that dreaded access denied error..</p>
  
  <p>I've also tried using CredSSP after setting up the WSManCredSSP (Client, delegation and Server) on the machines with no luck.</p>
  
  <p>I may have missed something, or is there a better way to handle such a case?</p>