11 Replies Latest reply on Mar 14, 2011 1:49 AM by csa

    Upgrade VM Guest NIC and other things using PowerCLI

    Zsoldier Expert
    vExpert

      Anyone figure out how to do this?  I'm trying to script the following process:

       

      • Script Upgrade VM Tools to current version.  <-- Done, grabbed from somewhere.  Using Update-Tools cmdlet after check
      Function Check-ToolsStatus($vm){
      $vmview = get-VM $vm | Get-View
      $status = $vmview.Guest.ToolsStatus
      if ($status -match "toolsOld"){
      $vmTools = "Old"}
      elseif($status -match "toolsNotRunning"){
      $vmTools = "Not Running"}
      else{
      $vmTools = "Ok"}
      return $vmTools
      }
      
      • Script Upgrade VM Hardware from 4 to 7.  <-- Done, grabbed from somewhere.
      Function Check-VMHardwareVersion($vm){
           $vmView = get-VM $vm | Get-View
           $vmVersion = $vmView.Config.Version
           $v4 = "vmx-04"
           $v7 = "vmx-07"
           
                if ($vmVersion -eq $v4){
                     $vmHardware = "Old"}
                elseif($vmVersion -eq $v7){
                     $vmHardware = "Ok"}          
                else{Write-Host "Error!!" -ForegroundColor Red
                     $vmHardware = "Error"}
                
                return $vmHardware
      }
      
      Function Upgrade-VMHardware($vm){
      
           $vmview = Get-VM $vm | Get-View
           $vmVersion = $vmView.Config.Version
           $v4 = "vmx-04"
           $v7 = "vmx-07"
      
                if ($vmVersion -eq $v4){
                     Write-Host "Version 4 detected" -ForegroundColor Red
                     
                     # Update Hardware
                     Write-Host "Upgrading Hardware on" $vm -ForegroundColor Yellow
                     Get-View ($vmView.UpgradeVM_Task($v7)) | Out-Null
           }     
      }
      
      • Script Copy current NIC configurations. <-- Not sure how to do this.  vbScript? netsh? using invoke-vmscript?
        • Needs to get full IP address config.
        • Needs to get current nic adapter attached network.
      ????
      
      • Script Add VMXNET 2 | 3 nic. <-- See below for idea.
      #My Thought
      New-NetworkAdapter -Type EnhancedVmxnet -NetworkName <from previous script> -vm <targetvm> -confirm:$false
      
        • Should remove old nic once settings have been transferred.
      #Probably a where statement would be better since I only want to remove non enhancedvmxnet and vmxnet3
      $nic = Get-NetworkAdapter -VM | Remove-NetworkAdapter -networkadapter $nic[0]
      
      • Script Apply copied NIC configs to new nic (VMXNET2 | 3) <-- Not sure how to do this. vbScript? netsh? using invoke-vmscript?

       

      ????
      

       

      • Script Add vmdisk, change controller to pvscsi, wait 30 sec for OS to detect.
      #My Thought
      $tempdisk = $vm | New-Harddisk -CapacityKB 2048 -StorageFormat Thin
      Sleep 30
      $vm | Shutdown-VMGuest -confirm:$false
      Sleep 90
      If ($vm.powerstate -eq "PoweredOn"){Stop-VM $vm -Confirm:$false}
      $tempdisk | New-ScsiController -Type Paravirtual
      Start-VM $vm -confirm:$false
      Sleep 90
      
      • Script to shutdown, remove added disk, and change current disks to pvscsi
      #My Thought
      $vm | Shutdown-VMGuest -confirm:$false
      Sleep 90
      If ($vm.powerstate -eq "PoweredOn"){Stop-VM $vm -Confirm:$false}
      $tempdisk = $vm | get-harddisk | where {$_.CapacityKB -eq "2048"}
      $tempdisk | Remove-HardDisk
      $vm | get-harddisk | set-scsicontroller -type paravirtual -confirm:$false
      Start-VM $vm -confirm:$false
      

       

      Message was edited by: Zsoldier