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.
CodePudding user response:
What about using this following in a .cmd file:
powershell -executionpolicy bypass -noexit "& ""C:\your\path\to\domainjoinscript.ps1"""
from
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