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

Create New Custom Attribute to User Class

Log onto Domain Controller Schema Master with an account belong to the group Schema Admin…

Invoke Commands on Remote Computers [To Install Applications]

$computers=@( 'pc1', 'pc2' ) $commandString="choco install pgadmin4 -y --ignore-checksums" function invokeCommand{ param( $computers, $commandString, $credentials…

PowerShell: Setting or Resetting User Password

$username='dragoncoin' $newPassword='SomeComplexPasswordHere' function resetPassword($username,$password){ if($env:userdnsdomain){ try{ Unlock-ADAccount -Identity $username Set-ADAccountPassword -Identity $username -Reset -NewPassword (ConvertTo-SecureString…