Powershell remoting with active directory

active-directorypowershell

I am able to connect to domain controller via below scrip remotely, but after that i want to run disable-ADAccount ,Get-ADUser command but I am getting error

Get-ADUser : The server has rejected the client credentials.

How can I call active directory command in single script file?

$password = ConvertTo-SecureString "Password" -AsPlainText -Force
$cred= New-Object System.Management.Automation.PSCredential ("Lab\dcadmin", $password)
Enter-PSSession -ComputerName dc-01 -Port 5985 -Credential $cred

Best Answer

Try this: On a computer joined to the domain in question, right-click on the Powershell Start Menu icon or shortcut and choose "Run as administrator". Enter the credentials of a Domain Administrator account. Then try the Powershell commands. They should run in the context of a Domain Administrator account and you should have no authorization problems.

Note, if you are logged on to the domain-joined computer with a local admin account, this might not work, because when you choose "Run as administrator" it will run it as a local administrator without prompting for credentials. Either log on to the computer as a user who is not an administrator or as a Domain Administrator.