0

I am trying to run this from a .cmd with run as administrator

powershell -Command "&{ Start-Process powershell Add-Computer -Domain "domain.domain" -Credential login -Verb RunAs -Wait -Confirm}"

The window to input password does pop up, but after I input the password I am greeted with the following error on my batch script.

Start-Process : O conjunto de parâmetros não pode ser resolvido usando os parâmetros nomeados especificados.
No linha:1 caractere:4
+ &{ Start-Process powershell Add-Computer -Domain domain.domain -Cr ...
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.StartProcessCommand

I want to join a domain via scripting, I tried to use netdom, but it's exclusive to servers. I am dealing with client notebooks with Windows 10, very far from the server, and I don't have any admin access to the server domai. I am just formatting a huge amount of computers to a specified state, and that includes joining then on a domain. I don't care how I join the domain as long as I join the domain automatically, (if impossible asking for password is acceptable), from a batch or powershell script, and without instaling anything.

  • Also note the owner-only join hardening since the october 2022 update: https://support.microsoft.com/en-us/topic/kb5020276-netjoin-domain-join-hardening-changes-2b65a0f3-1f4c-42ef-ac0f-1caaf421baf8 – js2010 Dec 07 '22 at 14:17

1 Answers1

0

What about using this following in a .cmd file:

powershell -executionpolicy bypass -noexit "& ""C:\your\path\to\domainjoinscript.ps1"""

from

How to run a PowerShell script

The -executionpolicy bypass flag is because by default, PowerShell doesn't let you run un-trusted scripts (even if you created them). Either you have to disable the Execution Policy system-wide, or do it like this.

Your .ps1 file should contain:

add-computer -domainname "yourdomain" -restart
  • Thank you! That solved my problem, now i run in another problem... just before i run this script i change the computer name with this... ... set /P newname="what is the computer name? " wmic computersystem where name='%computername%' call rename name='%newname%' ... But i can not join domain because the previous name is still in use... do you know some way i can bypass the need to do two computer restarts? one for rename and one for the domain? – Guilherme Polizel Dec 07 '22 at 12:58
  • $env:computername has the computername. You should be able to rename and join in one reboot like in the control panel, but I've had trouble with it. Is -noexit necessary? Won't you need domain credentials? – js2010 Dec 07 '22 at 14:25