Link to home
Start Free TrialLog in
Avatar of Jesse Mayfield
Jesse Mayfield

asked on

Powercli - Changing network adapter after customization has finished. Script

Hi, I'm trying to add to my current script to have the network adapter changed after the customization and vm has powered off. I have been able to run the script to rename the network adapter successfully. I don't know how to place it in my current working script. Here is what i have
get-vm testvm | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName = vlan500 -Confirm:$false

Open in new window


# Specify vCenter Server, vCenter Server username and vCenter Server
user password
$vCenter=
$vCenterUser=
$vCenterUserPassword=
#
# Create all the VMs specified in $newVmList
$newVmList = ...
#
# Specify the VM you want to clone
$mySourceTemplate = Get-Template -Name "win2k12R2stdenhanced_template"
#
# Specify the Customization Specification to use
$customspecification=”Windows_2012_std_R2_template"
#
# Specify the datastore or datastore cluster placement
$ds = "CORE_Test_1"
#
$vmhost = Get-VMHost -Name corevhost
#
# Specify vCenter Server Virtual Machine & Templates folder
$Folder = "Templates"
#
# Specify the vSphere Cluster
$Cluster = "CORE"
#
# Specify the VM name to the left of the – sign
$VM_prefix = "test1-"
#
# End of user input parameters
#_______________________________________________________
#
write-host "Connecting to vCenter Server $vCenter” -foreground green
Connect-viserver $vCenter -user $vCenterUser -password $vCenterUserPassword -WarningAction 0
$newVmList | ForEach-Object {
	$VM_name= $_
	$ESXi=Get-Cluster $Cluster | Get-VMHost -state connected | Get-Random
	write-host "Creation of VM $VM_name initiated” -foreground green
	New-VM -Name $VM_Name -Template $mySourceTemplate -VMHost $ESXi -Datastore $ds -Location $Folder -OSCustomizationSpec $customspecification
	Start-VM $VM_Name
	Start-Sleep 300   # seconds
	Stop-VM $VM_Name -RunAsync
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jesse Mayfield
Jesse Mayfield

ASKER

Thanks again Qlemo!!!