none
Script to join machine in domain using powershell RRS feed

  • Question

  • Hi,

    I am using a powershell cmdlets to join the virtual machines which are created. These Virtual machine are created in automated on large scale. I want to use following script to join these Virtual machine to our domain. This script will be executed on each VM.

    if ( ! ((gwmi win32_computersystem).partofdomain -eq $true ) -and (((gwmi win32_computersystem).domain -eq 'domainname')))
    { add-computer -DomainName persistent.co.in -Credential  persistent\<username> -password * -force -restart }

    Queries :-

    1. I don't want to mention password in the script neither i want the prompt which ask user name and password. Can we do some think so that the plain text password becomes blank or any think which can not be read by user when we opens the script but when we run this script the power shell should conder stand the password.

    Monday, October 27, 2014 2:01 PM

Answers

  • You cannot share a password between machines.

    Use MDT.  It can safely join a machine during deployment and provisioning.


    ¯\_(ツ)_/¯

    Thursday, October 30, 2014 6:31 AM

All replies

  • if ( ! ((gwmi win32_computersystem).partofdomain -eq $true ) -and (((gwmi win32_computersystem).domain -eq 'domainname')))
     { add-computer -DomainName persistent.co.in -Credential  (Get-Credential -Credential 'Domain\Admin') -force -restart }


    Regards Chen V [MCTS SharePoint 2010]


    • Edited by Chen VMVP Monday, October 27, 2014 4:30 PM
    • Proposed as answer by jrv Tuesday, October 28, 2014 2:21 PM
    Monday, October 27, 2014 2:09 PM
  • The short answer is no, you can't put a plaintext password in your script and hide it from your users.


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Monday, October 27, 2014 2:17 PM
  • Thanks for pointing out jrv.

    Regards Chen V [MCTS SharePoint 2010]

    Monday, October 27, 2014 4:30 PM
  • Hi

    Is there any alternative like can i delete the script once its completed after the execution ? I want to avoid writing another script which deletes the machine domain joining script where password is mentioned.

    Please suggest.

    Tuesday, October 28, 2014 2:14 PM
  • Hi

    Is there any alternative like can i delete the script once its completed after the execution ? I want to avoid writing another script which deletes the machine domain joining script where password is mentioned.

    Please suggest.

    The script posted does not save the password anywhere.


    ¯\_(ツ)_/¯

    Tuesday, October 28, 2014 2:21 PM
  • Thanks JRV,

    Actually i am going to run this script on number of VMs and it will be a automated. USer interaction will be not there to run the script. Get-credential needs a input from user. So i can not you get-credential here.

    Please suggest if any possiblity.

    Thank all.

    Thursday, October 30, 2014 6:25 AM
  • You cannot share a password between machines.

    Use MDT.  It can safely join a machine during deployment and provisioning.


    ¯\_(ツ)_/¯

    Thursday, October 30, 2014 6:31 AM
  • Thanks All.

    I will go with MDT.

    Friday, October 31, 2014 4:37 AM