[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 14889
  • Last Modified:

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
0
Philip Elder
Asked:
Philip Elder
  • 10
  • 8
1 Solution
 
bosjayiCommented:
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
0
 
BSonPoshCommented:
What you are looking for is Add-Computer

help add-computer -full
0
 
Philip ElderTechnical Architect - HA/Compute/StorageAuthor Commented:
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
BSonPoshCommented:
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

0
 
Philip ElderTechnical Architect - HA/Compute/StorageAuthor Commented:
BsonPosh,

Getting closer! :)

Errors out. See attached.

Philip

09-02-17-PowerShell-Error.PNG
0
 
BSonPoshCommented:
oh... you need to quote the OU
0
 
Philip ElderTechnical Architect - HA/Compute/StorageAuthor Commented:
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. :(
0
 
BSonPoshCommented:
same error?

-computername is the hostname
-server is DC you want to perform the join on
0
 
Philip ElderTechnical Architect - HA/Compute/StorageAuthor Commented:
Get prompted twice.

Then, see attached.

Thanks. Philip
09-02-17-PowerShell-Domain-Add-E.PNG
0
 
BSonPoshCommented:
That is authentication error.
0
 
Philip ElderTechnical Architect - HA/Compute/StorageAuthor Commented:
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
0
 
BSonPoshCommented:
Those are the domain creds. I assume you are local the Win7 host?
0
 
Philip ElderTechnical Architect - HA/Compute/StorageAuthor Commented:
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
0
 
BSonPoshCommented:
Philip, at this point, I think this is a bug.
0
 
Philip ElderTechnical Architect - HA/Compute/StorageAuthor Commented:
Ouch... :P

Got it.

Philip
0
 
BSonPoshCommented:
I just got word... this already fixed and should be in the next release
0
 
Philip ElderTechnical Architect - HA/Compute/StorageAuthor Commented:
Okay.
Thanks for that!
Philip
0
 
Philip ElderTechnical Architect - HA/Compute/StorageAuthor Commented:
Oops ... clicked on the wrong one initially.
Philip
0
 
Philip ElderTechnical Architect - HA/Compute/StorageAuthor Commented:
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
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

  • 10
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now