title: Batch Script to rename computer and join to domain on a single click
body: <p>I have 200 domain computers and i need to change the host name and rejoin to domain on a click. </p>
  
  <ol>
  <li>First operation </li>
  </ol>
  
  <pre class="lang-ps1 prettyprint-override"><code>Powershell.exe "-ExecutionPolicy Bypass Add-Computer -DomainName &lt;Domain Name&gt; -ComputerName &lt;Old_ComputerName&gt; -NewName &lt;New_ComputerName&gt; -$credential = New-Object System.Management.Automation.PSCredential($username = "&lt;Domain\User ID&gt;", ($password = &lt;Password&gt; | ConvertTo-SecureString -asPlainText -Force))" 
  </code></pre>
  
  <ol start="2">
  <li>Second operation</li>
  </ol>
  
  <pre class="lang-bat prettyprint-override"><code>net user Administrator &lt;Password&gt;
  </code></pre>
  
  <ol start="3">
  <li>Restart computer</li>
  </ol>
  
  <p>But, While executing the above script in cmd with elevated privileges. I am getting the below error. </p>
  
  <pre class="lang-ps1 prettyprint-override"><code>At line:1 char:206
  + ... ement.Automation.PSCredential($username = Domain\User ID, ($passw ...
  +                                                                 ~
  Missing argument in parameter list.
      + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
      + FullyQualifiedErrorId : MissingArgument  
  </code></pre>
  
  <p>We are looking for a single line command to do the above operation.</p>