Posted On April 26, 2022

PowerShell: How To Configure Static IP Address

kimconnect 0 comments
blog.KimConnect.com >> Codes , Windows >> PowerShell: How To Configure Static IP Address
$nicName='NIC1'
$ipaddress='192.168.0.222'
$cidrPrefix=24
$defaultGateway='192.168.0.1'
$dnsServers=@('8.8.8.8','4.4.2.2')
$disableIpv6=$true

function setNic($nicName,$ipAddress,$cidrPrefix,$defaultGateway,$dnsServers,$disableIpv6=$true ){
	$ifIndex=(get-netadapter|?{$_.Name -eq $nicName}).ifIndex
	New-NetIPAddress -InterfaceIndex $ifIndex -IPAddress $ipaddress -PrefixLength $cidrPrefix -DefaultGateway $defaultGateway
	Set-DnsClientServerAddress -InterfaceIndex $ifIndex -ServerAddresses $dnsServers
	if($disableIpv6){Disable-NetAdapterBinding -Name $nicName –ComponentID ms_tcpip6}
}
setNic $nicName $ipAddress $cidrPrefix $defaultGateway $dnsServers $disableIpv6

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Batch File to Copy Files Containing Agents’ Names

:: Set variables using system time and date popd   Set today=%Date:~4,2%_%Date:~7,2%_%Date:~10,4%   IF "%today:~0,1%"=="0"…

PowerShell: Comparing 2 Directories

# Set source and destination$source="C:\temp"$destination="C:\tempcopy"# Mirror the 2 directoriesrobocopy $source $destination /MIR /R:0 /NP# create…

How to Install Asterisk on Ubuntu

su[enter root password]cd /tempwget apt-get install build-essential wget libssl-dev libncurses5-dev libnewt-dev libxml2-dev linux-headers-$(uname -r) libsqlite3-dev…