Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

PowerShell – Set IP Address

Posted on November 9, 2015 By David Kittell
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 = $(read-host "Enter the second DNS Server (ie 10.2.0.28)"),
			[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)		
}

Reference: http://poshcode.org/6000

All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code PowerShell

Post navigation

Previous post
Next post

Related Posts

Get Number Of Rows Deleted

Posted on August 1, 2013October 26, 2015

DELETE FROM Files WHERE FileID = 1 SELECT @@ROWCOUNT AS DELETED; Originally Posted on August 1, 2013Last Updated on October 26, 2015 All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested…

Read More

PowerShell Special Folders

Posted on September 17, 2015

$SpecialFolders = @{} $names = [Environment+SpecialFolder]::GetNames([Environment+SpecialFolder]) foreach($name in $names) { if($path = [Environment]::GetFolderPath($name)){ Write-Host $name "`r`n" $path } } Named Special Folders: Desktop Programs Personal MyDocuments Favorites Startup Recent SendTo StartMenu MyMusic DesktopDirectory Templates ApplicationData LocalApplicationData InternetCache Cookies History CommonApplicationData System ProgramFiles MyPictures CommonProgramFiles All information on this site is…

Read More

PowerShell – Show File Extensions

Posted on August 30, 2016

function ShowFileExtensions() { # http://superuser.com/questions/666891/script-to-set-hide-file-extensions Push-Location Set-Location HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced Set-ItemProperty . HideFileExt "0" Pop-Location Stop-Process -processName: Explorer -force # This will restart the Explorer service to make this work. } ShowFileExtensions function HideFileExtensions() { # http://superuser.com/questions/666891/script-to-set-hide-file-extensions Push-Location Set-Location HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced Set-ItemProperty . HideFileExt "1" Pop-Location Stop-Process -processName: Explorer -force # This will…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - IIS Remove Site
  • Front Page
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories
  • Raspberry Pi - Remove Default Apps
  • PowerShell - Change Windows CD/DVD Drive Letter
©2025 David Kittell | WordPress Theme by SuperbThemes