Add workstations to Domain using powershell

Copper Contributor

Team,

 

I am looking for a PS script to add multiple workstations to Domain, i used the below command to add, but firewall is blocking in adding and restarting, can some one help me with the correct script.

script should take the workstations from txt file.

Add-Computer -ComputerName $Computer -DomainName $domain -Credential $credential -Restart -Force .

2 Replies

@Srikanth_satya 

 

Hi, Srikanth.

 

There's nothing wrong with your PowerShell example.

 

The method you've chosen relies on connecting via RPC, which by your comment about the Windows Firewall isn't permitted by the remote clients. You could try the WinRM approach but my guess is this will fail for exactly the same reason (i.e. Windows Firewall rejecting it):

 

Invoke-Command -ComputerName $Computer -ScriptBlock {
    param($domain, $credential);
    Add-Computer -DomainName $domain -Credential $credential -Restart -Force
} -ArgumentList $domain, $credential;

 

If the target machines are not domain-joined (i.e. they're workgroup machines) then there's nothing you can do remotely to bypass the Windows Firewall on those clients.

 

If the target machines are domain-joined, you could use domain-based group policy (assuming you have the appropriate access to the domain they've currently joined to) to configure both WinRM and the Windows Firewall to allow access, but my guess is that you're dealing with the above workgroup scenario.

 

Whichever the scenario, this isn't a PowerShell issue.

 

Cheers,

Lain

@LainRobertson Thank you so much for your advice, yes. basically my requirement is to join 50 workstation to domin which are in workgroup, i need to perform this remotely.

Firewall is stopping to add the workstations.

1. can i turn off the firewall through ps command and run add-computer command to join workstations to domin.

2. looking for a single command using foreach and invoke.

 

Thanks