Hello,
I came across a very useful PowerShell script called the ultimate deploy script located here: http://vmwaremine.com/2014/08/25/ultimate-vm-batch-deployment-script/#sthash.lcr1zd15.sz9kvVKi.dpbs
I'm attempting to modify this script to allow me to update the assigned portgroup on a newly created VM after deploying it from a template.
The -template and -NetworkName / -Portgroup parameter are in different parameter sets, so I'm attempting to modify the VM after the New-VM task completes.
Originally I attempted to access the $vms variable right above line #214 with the $batch and $index variables as well with $vms[$batch + $index], then I realized the $index will be way out of bounds as it's incremented in the code block above.
Additionally on line #379 I was attempting to make the $vms2deploy variable global so I can access $vms2deploy above line #214 and grab the portgroup information from my CSV by comparing the name of the VM in $vms2deploy with the $newvm_tasks[$_.id] variable, which should hold the name of the VM itself.
Which looked something like:
Line #380 : Set-Variable -Name vms2deployGlobal -value $vms2deploy
Line #214 $myVMName = $vms2DeployGlobal | where { $_.name -eq $newvm_tasks[$_.id] }
Get-VM $myVMName | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $myVMName.portgroup
This script has been immensely helpful, though I don't want to have to conduct a manual operation to change the portgroups every time we deploy from a template.
Thanks,
Message was edited by: aisrambler I didn't have the proper syntax for the where cmdlet
On line 214 the script starts the newly created VM.
The name of the VM is obtained from $newvm_tasks[$_.id].
Before the Start-VM you could do the Set-NetworkAdapter, something like this
Get-NetworkAdapter -VM $newvm_tasks[$_.id] |
Set-NetworkAdapter -NetworkName <your-desired-portgroup> -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you LucD for the fast response.
I'm having trouble accessing the portGroup name from the CSV to pass into Set-NetworkAdapter within the code block on Line 214.
Any suggestions on how I may pass that into Set-NetworkAdapter?
The example CSV in that post doesn't have a column for a destination portgroup, so you will have to add one.
Let's call the column "portgroup".
You could create a hash table with the VM name as key, and that portgroup as value.
When you are ready to do the Set-NetworkAdapter, you can find back the destination portgroup (you have the VM name at that point)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference