VMware Cloud Community
MayurPatel
Expert
Expert

How to copy and replace .nvram file

I have this simple but effective powercli script for deploying mass virtual machines from a CSV file that I developed with Luc's assistance and community help which I have been using it for my training lab.

Import-CSV b:\automate\lanservers.csv -UseCulture | %{

        $vm = New-VM -VMhost $ESXhost -Name $_.VMName -MemoryMB $_.MemoryMB -NumCPU $_.NumCPU -Version $_.Version -GuestId $_.GuestId -Floppy -Datastore $_.Datastore -DiskGB $_.DiskGB -DiskStorageFormat "Thin" -resourcepool $_.RPool -Notes $_.Notes -CD

        Get-CDDrive -VM $vm | Set-CDDrive -ISOPath $_.ISOPath -StartConnected $true -Confirm:$false

        Get-NetworkAdapter -VM $vm | Set-NetworkAdapter -NetworkName $_.NetworkName -Confirm:$False

        Get-FloppyDrive -VM $vm | Set-FloppyDrive -FloppyImagePath $_.FloppyPath -StartConnected $true -Confirm:$false

        $vm.ExtensionData.ReconfigVM_Task($vmConfigSpec)

      

    }

This has been working quite well for my present needs but there is one task I still have to do for optimizing the BIOS settings for disabling the I/O Advanced settings for Serial/Parallel ports and Floppy. Since these are BIOS settings I take it there is no way to manipulate these settings using a script. The only way is to copy a per-configured .nvram file and copy and replace the .nvram file which gets created as part of the VM creations process.

I need some help how to add the below process to my above script which will do the following after each VM is created:

1. Delete the existing VM1.vram file in the VM folder

2. Copy from a datastore location ie. Host_Local\NVRAM\template.nvram to each VM folder  (I could add the path to the nvram file in my CSV file)

3. Using the $vm variable rename template.nvram to the VM name

Many thanks

MP

Tags (3)
0 Kudos
2 Replies
LucD
Leadership
Leadership

You can use the datastore provider that is included in PowerCLI.

Have a look at 6.  Re: script to check a setting in a vmx file for specific entry where it is used to copy a VMX file in both directions.

It should be trivial to copy the nvram file in one direction from a model nvram file.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
MayurPatel
Expert
Expert

I had a look at the example you pointed me to  .Re: script to check a setting in a vmx file for specific entry

I can see where you are coming from i.e. copy the pre-set .nvram file and modify the vmx file with the name of the copied .nvram file type of thing? To be honest I kind of got lost in being able to understand the logic of how I could adapt it to either do the above or more simply copy a pre-defined .nvram file from one datastore and copy it to the VM folder and rename it to VM Name.

What I tried to do with my limited scripting know how is something simple like the below but it does not work.

Import-CSV b:\automate\lanservers.csv -UseCulture | %{

        $vm = New-VM -VMhost $ESXhost -Name $_.VMName -MemoryMB $_.MemoryMB -NumCPU $_.NumCPU -Version $_.Version -GuestId $_.GuestId -Floppy -Datastore $_.Datastore -DiskGB $_.DiskGB -DiskStorageFormat "Thin" -resourcepool $_.RPool -Notes $_.Notes -CD

        Get-CDDrive -VM $vm | Set-CDDrive -ISOPath $_.ISOPath -StartConnected $true -Confirm:$false

        Get-NetworkAdapter -VM $vm | Set-NetworkAdapter -NetworkName $_.NetworkName -Confirm:$False

        Get-FloppyDrive -VM $vm | Set-FloppyDrive -FloppyImagePath $_.FloppyPath -StartConnected $true -Confirm:$false

Copy-DatastoreItem vmstore:\Build\LabBuild\template.nvram $_.Datastore\$_.VMName\$vm.nvram

        $vm.ExtensionData.ReconfigVM_Task($vmConfigSpec)

      

    }

0 Kudos