PoshCode Archive  Artifact [d5c6d5d086]

Artifact d5c6d5d086fff9a787d3ee54da9ccb96eb13d804905a93297307582b1d8ec670:

  • File Set-IPAddress.ps1 — part of check-in [06130613db] at 2018-06-10 13:28:08 on branch trunk — A function to set an IP Address (user: Robert size: 1336)

# encoding: ascii
# api: powershell
# title: 
# description: A function to set an IP Address
# version: 192.168.1.1
# type: function
# author: Robert
# license: CC0
# function: Set-IPAddress
# x-poshcode-id: 3599
# x-derived-from-id: 3602
# x-archived: 2012-09-05T10:24:27
# x-published: 2012-08-28T11:46:00
#
# Andy Schneider
# Get-PowerShell.com
#
function Set-IPAddress {
		param(	[string]$networkinterface =$(read-host "Enter the name of the NIC (ie Local Area Connection)"),
			[string]$ip = $(read-host "Enter an IP Address (ie 10.10.10.10)"),
			[string]$mask = $(read-host "Enter the subnet mask (ie 255.255.255.0)"),
			[string]$gateway = $(read-host "Enter the current name of the NIC you want to rename"),
			[string]$dns1 = $(read-host "Enter the first DNS Server (ie 10.2.0.28)"),
			[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)
		
}