Addning vmware vm to AD with Invoke-VMscript

Adding a new Vmware VM to Active Directory without using Customization Specifications proved to be a challenge.

Since the VM was newly created from a template with firewall enabled I was forced to use Invoke-VMscript to get into to the server. After adding it to the domain and moving it to a OU with a GPO disabling the firewall I can then continue the customization of the VM with ordinary Invoke-Command. Attaching with Invoke-Command between a domain connected  Vm and a workgroup VM unfortunately was not possible because of Kerberos authentication issues.

It’s not good practice not write username and Password in clear text in a script like this, but using Get-Credential and store it in a variable did not work for some reason.

So this did not work for some reason, just freeze:

$domainAdminCredentials = (Get-Credential)
$script="Add-Computer -Domainname domain.net -Credential $cred -restart -force"
$GuestCredential = (Get-Credential)
Invoke-VMScript -VM $targetvm -ScriptText  $script  -GuestCredential $GuestCredential

But this works:

$cmd4 = @'
$password = 'password' | ConvertTo-SecureString -asPlainText -Force
$username = 'domain/username'
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Add-Computer -Credential $credential -DomainName 'doamin.net' -Restart -force
'@
$paramInvoke = @{
VM = $targetvm
GuestCredential = $GuestCredential
ScriptType = 'Powershell'
ScriptText = $cmd4
}
Invoke-VMScript @paramInvoke

Advertisements
This entry was posted in AD, powershell, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s