1.# see
http://msdn2.microsoft.com/en-us/library/bb201634.aspx 2.# 3.# *NdisDeviceType 4.# 5.# The type of the device. The default value is zero, which indicates a standard 6.# networking device that connects to a network. 7.# 8.# Set *NdisDeviceType to NDIS_DEVICE_TYPE_ENDPOINT (1) if this device is an 9.# endpoint device and is not a true network interface that connects to a network. 10.# For example, you must specify NDIS_DEVICE_TYPE_ENDPOINT for devices such as 11.# smart phones that use a networking infrastructure to communicate to the local 12.# computer system but do not provide connectivity to an external network. 13.# 14.# Usage: run in an elevated shell (vista/longhorn) or as adminstrator (xp/2003). 15.# 16.# PS> .\fix-vmnet-adapters.ps1 17.
18.# boilerplate elevation check 19.
20.$identity = [Security.Principal.WindowsIdentity]::GetCurrent() 21.$principal = new-object Security.Principal.WindowsPrincipal $identity 22.$elevated = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) 23.
24.if (-not $elevated) { 25. $error = "Sorry, you need to run this script" 26. if ([System.Environment]::OSVersion.Version.Major -gt 5) { 27. $error += " in an elevated shell." 28. } else { 29. $error += " as Administrator." 30. }
31. throw $error 32.}
33.
34.function confirm { 35. $host.ui.PromptForChoice("Continue", "Process adapter?", 36. [Management.Automation.Host.ChoiceDescription[]]@("&No", "&Yes"), 0) -eq $true 37.}
38.
39.# adapters key 40.pushd 'hklm:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}' 41.
42.# ignore and continue on error 43.dir -ea 0 | % {
44. $node = $_.pspath 45. $desc = gp $node -name driverdesc 46. if ($desc -like "*vmware*") { 47. write-host ("Found adapter: {0} " -f $desc.driverdesc) 48. if (confirm) { 49. new-itemproperty $node -name '*NdisDeviceType' -propertytype dword -value 1 50. }
51. }
52.}
53.popd
54.
55.# disable/enable network adapters 56.gwmi win32_networkadapter | ? {$_.name -like "*vmware*" } | % { 57.
58. # disable 59. write-host -nonew "Disabling $($_.name) ... " 60. $result = $_.Disable() 61. if ($result.ReturnValue -eq -0) { write-host " success." } else { write-host " failed." } 62.
63. # enable 64. write-host -nonew "Enabling $($_.name) ... " 65. $result = $_.Enable() 66. if ($result.ReturnValue -eq -0) { write-host " success." } else { write-host " failed." } 67.}