I want to be able change from Bridged to NAT on a running VM and have it take effect immediately. I need to do this with a script. How can I do it?
My host is Vista. My guest is Server 2003. I am running VMware server 2x
netsh interface set interface <interface name> [ENABLED|DISABLED]
netsh interface set interface “Local Area Connection” DISABLED
netsh interface set interface “Local Area Connection” ENABLED
vmware-cmd (path to VMX file) setconfig ethernet0.connectionType="nat"
Connection Options:
-H <host> specifies an alternative host (if set, -U and -P must also be set)
-O <port> specifies an alternative port
-U <username> specifies a user
-P <password> specifies a password
$VMCore = Get-PSSnapin VMware.VimAutomation.Core -EA 0
if ( -not $VMCore ) { Add-PSSnapin VMware.VimAutomation.Core };
[void][http://Reflection.Assembly|http://Reflection.Assembly]::LoadWithPartialName("VMware.VimAutomation.Core")
[void][http://Reflection.Assembly|http://Reflection.Assembly]::LoadWithPartialName("VMware.Vim")
[void][http://Reflection.Assembly|http://Reflection.Assembly]::LoadWithPartialName("VMware.VimAutomation.Types")
[void][http://Reflection.Assembly|http://Reflection.Assembly]::LoadWithPartialName("VMware.VimAutomation")
[void][http://Reflection.Assembly|http://Reflection.Assembly]::LoadWithPartialName("VMware.VimAutomation.Common")
[void][http://Reflection.Assembly|http://Reflection.Assembly]::LoadWithPartialName("VMware.VimAutomation.Client20")
[void][http://Reflection.Assembly|http://Reflection.Assembly]::LoadWithPartialName("VMware.Security.CredentialStore")
$chost = "192.168.1.1";
$cuser = "me";
$cpassword = "mypass";
$cport = 8333;
$cprotocol = "https";
Connect-VIServer -Server $chost -User $cUser -Password $cPassword -Port $cport -Protocol $cprotocol;
if ( $DefaultVIServer -eq $null)
{ Write-Host "Connection Failed!"; return $false }
else
{ Write-Host "Connected : " $DefaultVIServer.IsConnected;
## Lets assign some views to variables
$global:moServiceInstance = (get-view ServiceInstance);
$global:moHostSystem = Get-View -VIObject (Get-VMHost);
$global:DefaultVIServer = $DefaultVIServer;
};
#do something
Disconnect-VIServer -Server $global:DefaultVIServer -WhatIf:$False -Confirm:$false -EA 0;