Link to home
Start Free TrialLog in
Avatar of Philip Elder
Philip ElderFlag for Canada

asked on

PowerShell in Windows 7 - HowTo Add-Computer to specific OU?

In Windows 7, we need to use the PowerShell command to add a computer to a domain specific OU.

We used to use a netdom join command for Windows Vista and Server 2008. NetDom is not included with Win7 or Win2K8 R2 from what I can see.

So, we need to use PowerShell. The Add-Computer command should accomplish what we need, but I sure cannot get to the proper syntax using the Help or online.

The targeted OU: OU=Win7OU,OU=MyBusiness,OU=Computers,DC=MySBSDomain,DC=Local
Domain: MySBSDomain.local
Win7 non-domain joined name: MY-Win7Beta

I have tried many different iterations of the command with no success.

Here is one (with and without the "" on the OU fails):

PS C:\Users\Information Services> Add-Computer -Credential MySBSDomain\Administrator -OUPath "OU=Win7OU,OU=Computers,OU=MyBusiness,DC=MySBSDomain,DC=Local" -Passthru -Server MySBSDomain\MySBSServer -ComputerName MY-Win7Beta -DomainName MySBSDomain.local
Add-Computer : This command cannot be executed on target computer('MY-Win7Beta') due to following error: Access is denied.
At line:1 char:13
+ Add-Computer <<<<  -Credential MySBSDomain\administrator -OUPath "OU=Win7OU,OU=Computers,OU=MyBusiness,DC=MySBSDomain,DC=Local" -passthru -Server MySBSDomain\MySBSServer -ComputerName MY-Win7Beta -DomainName MySBSDomain.local
    + CategoryInfo          : InvalidOperation: (My-Win7Beta:String) [Add-Computer], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.AddComputerCommand

I am looking for the properly formatted syntax to run in PowerShell itself. This is priority number 1.

From there, a script would be good to go too.

Thanks.

Philip
Avatar of bosjayi
bosjayi

Have you looked at the quest AD Managment tools?
I know they have a new-QADObject and Move-QADObject that lets you add / move things around.  I use their cmdlets for all my AD manipulation, just havn't used these specific ones yet.

http://www.quest.com/powershell/activeroles-server.aspx
What you are looking for is Add-Computer

help add-computer -full
Avatar of Philip Elder

ASKER

Third party is out of the question.

Help did not cut it. I copy and pasted the full Help into a text file to compare its output with the standard Help output and it did nothing to augment the standard Help.

Need the syntax please.

Philip
try this
$creds = Get-credential
Add-Computer -comp ServerName -domainname YourDomainName -OUPath OU=testOU,DC=domain,DC=Domain,DC=com -cred $creds

Open in new window

BsonPosh,

Getting closer! :)

Errors out. See attached.

Philip

09-02-17-PowerShell-Error.PNG
oh... you need to quote the OU
Okay, quotes in place.
It is still stalling. :(

Changed -comp to -Server MySBSDomain\MySBSServer to get rid of another error. But, I am still hamstrung for the proper syntax. :(
same error?

-computername is the hostname
-server is DC you want to perform the join on
Get prompted twice.

Then, see attached.

Thanks. Philip
09-02-17-PowerShell-Domain-Add-E.PNG
That is authentication error.
Yes ... but to what? The local machine or the domain? Or, am I trying to connect the server "-Comp MySBSServer" to its already existing domain which is kinda the way I read the error and syntax?

Philip
Those are the domain creds. I assume you are local the Win7 host?
Yes.
I have launched PS elevated, the local user has local admin privileges as well.

The domain credentials are formatted: MySBSDomain\Administrator along with the necessary password.

Philip
Philip, at this point, I think this is a bug.
Ouch... :P

Got it.

Philip
ASKER CERTIFIED SOLUTION
Avatar of BSonPosh
BSonPosh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Okay.
Thanks for that!
Philip
Oops ... clicked on the wrong one initially.
Philip
Here is the syntax we are now using:
Add-Computer -DomainName Domain.local -Credential Domain\ADMIN -OUPath "OU=TDClients,OU=TDComputers,OU=TDBusiness,DC=Domain,DC=Local"

Philip