Anyone figure out how to do this? I'm trying to script the following process:
Function Check-ToolsStatus($vm){$vmview = get-VM $vm | Get-View$status = $vmview.Guest.ToolsStatusif ($status -match "toolsOld"){$vmTools = "Old"}elseif($status -match "toolsNotRunning"){$vmTools = "Not Running"}else{$vmTools = "Ok"}return $vmTools}
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 } }
????
#My Thought
New-NetworkAdapter -Type EnhancedVmxnet -NetworkName <from previous script> -vm <targetvm> -confirm:$false
#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]
????
#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
#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
Hi,
It will work certenly with the root user, but it is possible to enable changes with user from root group.Behind the two commandlets there are two perl scripts that you can find in C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\ folder. The scripts are GetVmGuestNetworkInterface_LinuxGuest and SetVMGuestNetworkInterface_LinuxGuest.
The Get script reads configuration from /etc/sysconfig/network-script/ifcfg* files and also executes ifconfig command. A little observation on the permissions of pointed files shows that the get commandlet will work with user from root group.
The Set script writes into configuration files in /etc/sysconfig/network-scripts/, so you should give write permission on root group if you want to use another user.
The linux machine in our test environement is RedHat Enterprise 5
Vitali
PowerCLI Team
ah, must watch this thread. will look for ideas to throw in and get an answer. i need this!
Hi,
* About changing the virtual nic type you can use the Set-NetworkAdapter commandlet.
Get-NetworkAdapter -VM $vm | Set-NetworkAdapter -Type EnhancedVmxnet
* About saving network configuration.
** You can use Get-VMGuestNetworkInterface and Set-VMGuestNetworkInterface to obtain/set infromation from Guest OS about the network adapter configuration like does the machine has statically assigned IP address or it takes one from DHCP, gateway, DNS, etc.
** Get-NetworkAdapter can give you information about the connected virtual network.
* Upgrading the version of virtual hardware could be made in single line:
Get-VM | where { $_.Version -eq "v4" } | Set-VM -Version v7 -confirm:$false
Vitali
PowerCLI Team
Get-VMGuestNetworkInterface is kicking back errors after requesting credentials.
'Connect to host service 'https://myvcenter/sdk' at port 902' the following error occured: 'Failed to resolve host'
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_VixWaitForJob_VixErr
or,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVmGuestNetworkInterface
So, I'm stuck at retrieving the network settings from the existing network adapters to be reapplied to the new adapters after they're added...
@vitalibaruh I'll give these a try, thanks.
For Linux (RHEL4/5/6) VM's what level of permissions on the guest OS are needed to get it's guest network information?
Can it be an account w/ sub-root permissions?
Message was edited by: Zsoldier
@DBofTLP Seems you need to connect to the vCenter server using it's FQDN. In your example:
You should connect in this method:
connect-viserver myvcenter.mydomain.com
Seems a fair bit that you would like to do.
Have you had a look at the VMware labs - they have a tool called Onyx that will help you in gathering code requirements for what you are trying to do.
See the following links:
http://www.get-virtual.info/2011/02/16/script-of-the-day-quick-and-easy-vmware-powershell-scripts/
http://download3.vmware.com/software/vmw-tools/onyx/Onyx_2.0.3910.32223.zip
the actual Labs page appears to be down at the moment . . but I am sure will be back soon.
Hi,
It will work certenly with the root user, but it is possible to enable changes with user from root group.Behind the two commandlets there are two perl scripts that you can find in C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\ folder. The scripts are GetVmGuestNetworkInterface_LinuxGuest and SetVMGuestNetworkInterface_LinuxGuest.
The Get script reads configuration from /etc/sysconfig/network-script/ifcfg* files and also executes ifconfig command. A little observation on the permissions of pointed files shows that the get commandlet will work with user from root group.
The Set script writes into configuration files in /etc/sysconfig/network-scripts/, so you should give write permission on root group if you want to use another user.
The linux machine in our test environement is RedHat Enterprise 5
Vitali
PowerCLI Team
Thanks, think I have enough info to sew up the pieces. Thanks.
Hi Zsoldier,
I am facing a similar task. Any chance you could share the final script once it's done?
Yeah, sure thing.
Great ... looking forward to it 😉