Forum Discussion
Add workstations to Domain using powershell
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