Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 203297

Join VM to a Domain Using PowerCLI

$
0
0

Hey Guys,

I am fairly new to PowerCLI and all. I am currently developing a script that allows me to join hundreds of VMs to a specified domain, the VMs have Windows 2012 and 2016. However, the problem I am encountering is that nothing is happening because I am not sure if the code is correct. I have also no idea how to put in the credentials that it would ask me in the VM. The code works within the VM after I provide the credentials, but it does not work when I run the script outside the VM environment. Any idea ?

The Code:

        $addDomain = "{

  

    $secpasswd1 = ConvertTo-SecureString 'password' -AsPlainText -Force

    $mycreds1 = New-Object System.Management.Automation.PSCredential ('username', $secpasswd1)

    Add-Computer -DomainName domainName  -Credential $mycreds1 -Restart -Force

    }"

    Invoke-VMScript -VM $VMName -ScriptText $addDomain -GuestCredential $mycreds

 

Thanks in advance for your help!


Viewing all articles
Browse latest Browse all 203297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>