Skip to content

Instantly share code, notes, and snippets.

@klyr
Created April 15, 2019 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klyr/845a889fb6c7804d89fa7069c54e22fa to your computer and use it in GitHub Desktop.
Save klyr/845a889fb6c7804d89fa7069c54e22fa to your computer and use it in GitHub Desktop.
VMware script executed by vmware tools
$vmlog = 'C:\Program Files\vmlogs\vmenv.log'
$getenv = "C:\Program Files\VMware\VMware Tools\vmtoolsd.exe" --cmd="info-get guestinfo.ovfEnv" > "C:\Program Files\vmlogs\vmenv.xml"
Invoke-Expression -Command $getenv
[xml]$vmenv = Get-Content $vmenvxml
$vmIP = $vmenv.Environment.PropertySection.Property | ?{ $_.key -like 'ip_address' } | select -expand value
$vmNetmask = $vmenv.Environment.PropertySection.Property | ?{ $_.key -like 'netmask' } | select -expand value
$vmGW = $vmenv.Environment.PropertySection.Property | ?{ $_.key -like 'default_ateway' } | select -expand value
$vmHostname = $vmenv.Environment.PropertySection.Property | ?{ $_.key -like 'hostname' } | select -expand value
$vmDNS = $vmenv.Environment.PropertySection.Property | ?{ $_.key -like 'dns_servers' } | select -expand value
$ifname = Get-NetAdapter | Select -expand Name
# Configure network
$vmdate = Get-Date -Format "MMddyyyy-hh:mm"ls
Write-Output $vmdate": Configuring Network settings" >> $vmlog
New-NetIPAddress –InterfaceAlias $ifname –IPAddress $vmIP –PrefixLength $vmNetmask -DefaultGateway $vmGW
Set-DnsClientServerAddress -InterfaceAlias $ifname -ServerAddresses $vmDNS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment