PoshCode Archive  Artifact [ba41080066]

Artifact ba41080066931c60f80da492409ddb9c2fdabb179ffa9c8040a74f7e32289701:

  • File Set-IPAddress.ps1 — part of check-in [dfcc266c36] at 2018-06-10 13:53:12 on branch trunk — A function to set an IP Address (user: Andy Schneider size: 1348)

# encoding: ascii
# api: powershell
# title: Set-IPAddress
# description: A function to set an IP Address
# version: 0.1
# type: function
# author: Andy Schneider
# license: CC0
# function: Set-IPAddress
# x-poshcode-id: 531
# x-derived-from-id: 1794
# x-archived: 2015-09-25T11:19:04
# x-published: 2008-08-18T17:54: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)
		
}