Script in VBS to change the IPv4 configuration from DHCP Enabled to DHCP disabled

I need an script in VBS to change the IPv4 configuration from "DHCP Enabled" to "DHCP disabled" but keeping all the actual NIC parameters that it has right now.
It must keep the same IP address, subnet, default gateway, dns, etc.

This is because my IP is changing week by week and i want to get them static now but keeping the same values at the moment of running the script in all the servers.
acunaaraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
It's not in the Topics list, but here's a Powershell version anyway that takes care of IP, Netmask, Gateway, DNS. It prompts for confirmation by default before changing the settings; start it with -Force to skip the confirmation.
Param(
	[switch]$Force
)

Function Get-IPSettings([Parameter(ValueFromPipeline=$true)]$Nic) {
	Process {
		$Nic | Select-Object -Property `
			Description,
			@{Name="IPv4Address"; Expression={$_.IPAddress | ? {$_ -match "^\d+\.\d+.\d+.\d+$"}}},
			@{Name="IPv4Subnet"; Expression={$_.IPSubnet | ? {$_ -match "^\d+\.\d+.\d+.\d+$"}}},
			DefaultIPGateway,
			DNSServerSearchOrder
	}
}

$DhcpNics = Get-WmiObject -Namespace "Root\CIMv2" -Query "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled='True' AND DHCPEnabled='True'"
"Found the following NIC(s) with DHCP configuration:" | Write-Host -Foregroundcolor White
$DhcpNics | Get-IPSettings | Format-List | Out-String | Write-Host -Foregroundcolor White

If (-Not $Force) {
	$Confirm = Read-Host "Proceed with converting these settings to static [y/N]"
}
If ($Force -Or ($Confirm -eq "y")) {
	ForEach ($Nic In $DhcpNics) {
		Try {
			"Processing '$($Nic.Description)':" | Write-Host -Foregroundcolor White
			$DhcpSettings = Get-IPSettings -Nic $Nic
			"- Static address $($DhcpSettings.IPv4Address -join ",")/$($DhcpSettings.IPv4Subnet -join ",") ..." | Write-Host -NoNewline -Foregroundcolor White
			$Result = $Nic.EnableStatic($DhcpSettings.IPv4Address, $DhcpSettings.IPv4Subnet)
			If ($Result.ReturnValue -eq 0) {
				" OK." | Write-Host -Foregroundcolor Green
				"- Gateway $($DhcpSettings.DefaultIPGateway -join ",") ..." | Write-Host -NoNewline -Foregroundcolor White
				$Result = $Nic.SetGateways($DhcpSettings.DefaultIPGateway)
				If ($Result.ReturnValue -eq 0) {
					" OK." | Write-Host -Foregroundcolor Green
				} Else {
					" ERROR $($Result.ReturnValue)!" | Write-Host -Foregroundcolor Red
					"See 'https://msdn.microsoft.com/en-us/library/aa393301(v=vs.85).aspx' for error details." | Write-Host -Foregroundcolor Yellow
				}
				"- DNS $($DhcpSettings.DNSServerSearchOrder -join ",") ..." | Write-Host -NoNewline -Foregroundcolor White
				$Result = $Nic.SetDNSServerSearchOrder($DhcpSettings.DNSServerSearchOrder)
				If ($Result.ReturnValue -eq 0) {
					" OK." | Write-Host -Foregroundcolor Green
				} Else {
					" ERROR $($Result.ReturnValue)!" | Write-Host -Foregroundcolor Red
					"See 'https://msdn.microsoft.com/en-us/library/aa393295(v=vs.85).aspx' for error details." | Write-Host -Foregroundcolor Yellow
				}
			} Else {
				" ERROR $($Result.ReturnValue)!" | Write-Host -Foregroundcolor Red
				"See 'https://msdn.microsoft.com/en-us/library/aa390383(v=vs.85).aspx' for error details." | Write-Host -Foregroundcolor Yellow
			}
		} Catch {
			" ERROR: $($_.Exception.Message)!" | Write-Host -Foregroundcolor Red
		}
	}
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
acunaaraAuthor Commented:
Excellent. Really what i need! Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.