PoshCode Archive  Artifact Content

Artifact 6954533b918ca6a2d9844fae5bef20be570980ab496a9fe099525a53de60afdf:

  • File Set-IPAddress.ps1 — part of check-in [20d3aa81bd] at 2018-06-10 13:01:31 on branch trunk — A function to set an IP Address (user: Shane Powser size: 1052)

# encoding: ascii
# api: powershell
# title: Set-IPAddress
# description: A function to set an IP Address
# version: 0.1
# type: script
# author: Shane Powser
# license: CC0
# function: Set-IPAddress
# x-poshcode-id: 1806
# x-archived: 2010-05-01T15:42:39
#
# Andy Schneider
# Get-PowerShell.com
#
# ahhh ... much better. Don't ask for prompts. It's not scriptable if you do.

function Set-IPAddress {
		param(	[string]$networkinterface,
			[string]$ip,
			[string]$mask,
			[string]$gateway,
			[string]$dns1,
			[string]$dns2,
			[string]$registerDns=$true
		 )
		$dns = $dns1
		if($dns2){$dns ="$dns1","$dns2"}
		$index = (gwmi Win32_NetworkAdapter | where {$_.netconnectionid -eq $networkinterface}).InterfaceIndex
		$NetInterface = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $index}
		$NetInterface.EnableStatic($ip, $subnetmask)
		$NetInterface.SetGateways($gateway)
		$NetInterface.SetDNSServerSearchOrder($dns)
		$NetInterface.SetDynamicDNSRegistration($registerDns)
		
}