Team,
Using the below Script i am able to deploy the VM (OS - Win2k8R2) but its not oining the domain. Could someone assist me.
$Domainuser = ""
$LocalUser = Read-Host "Type Local Admin"
$LocalPass = Read-Host "Type local Admin Pass" -AsSecureString
#$getcredential = Get-Credential
$domainpassword = Read-Host "type domain password" -AsSecureString
$viserver = Read-Host "Enter VC Name"
Connect-VIServer $viserver
Import-Csv "C:\PS\newserverdeploy.csv" -UseCulture | %{
#-----------------------------------------------------------------------------------
#Create AD Object
#-----------------------------------------------------------------------------------
$Server = $_.ServerName
#-----------------------------------------------------------------------------------
#Create DNS Entry
#-----------------------------------------------------------------------------------
Remove-OSCustomizationSpec $_.customizationName -Confirm:$false
$Randomhost = Get-Cluster $_.clustername | Get-VMHost | where {$_.state -notmatch "Maintenance"} | get-random
$portgroup = $Randomhost | Get-VirtualPortGroup | select name
$inputportgrp1 = $_.inputportgrp1
$portgroup | ForEach-Object {if ($_.Name -match $inputportgrp1) {
$Networkname1 = $_.name
Write-Host $networkname1
}}
$inputportgrp2 = $_.inputportgrp2
$portgroup | ForEach-Object {if ($_.Name -match $inputportgrp2) {
$Networkname2 = $_.name
Write-Host $networkname2
}}
Get-OSCustomizationSpec $_.customizationname | Set-OSCustomizationSpec -FullName $localuser -AdminPassword $localpass -domain "" -DomainUsername $Domainuser -DomainPassword $domainpassword -AutoLogonCount 2 -Confirm:$false
Get-OSCustomizationSpec $_.customizationname | Get-OSCustomizationNicMapping | where { $_.Position -eq '1'} | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $_.ip1 -SubnetMask $_.subnet1 -DefaultGateway $_.Gateway1 -Dns $_.dns1,$_.dns2
New-vm -Name $Server -VMhost $randomhost -Template $_.Template -Datastore $_.Datastore -OSCustomizationspec $_.customization
Start-Sleep -Seconds 10
Set-VM $_.Servername -MemoryMB $_.Memory -Confirm:$false
Start-Sleep 10
Set-VM $_.Servername -NumCpu $_.CPU -Confirm:$false
Start-VM $_.servername
Start-Sleep -Seconds 60
Get-NetworkAdapter -VM $_.ServerName | where {$_.Name -match "1"} | Set-NetworkAdapter -NetworkName $Networkname1 -Connected:$true -StartConnected:$true -Confirm:$false
Get-NetworkAdapter -VM $_.ServerName | where {$_.Name -match "2"} | Set-NetworkAdapter -NetworkName $Networkname2 -Connected:$true -StartConnected:$true -Confirm:$false
Start-Sleep -Seconds 30
}