-
-
Save klyr/845a889fb6c7804d89fa7069c54e22fa to your computer and use it in GitHub Desktop.
VMware script executed by vmware tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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