carlessanagustin
2/4/2015 - 12:50 PM

(PowerShell) Request static IP configuration and place it into a text file

(PowerShell) Request static IP configuration and place it into a text file

## An A-Z Index of Windows PowerShell 2.0 commands: http://ss64.com/ps/

do {
	$ip = Read-Host "Enter IP address"
	$mask = Read-Host "Enter mask"
	$gw = Read-Host "Enter default gateway"
	Write-Host 'Is this information correct? IP $ip MASK $mask GW $gw'
	$confirm = Read-Host "yes/no"
}while ($confirm -notlike "yes")

$text = 'sudo ifconfig eth0 $ip netmask $mask`n
sudo route add default gw $gw eth0`n
nameserver 8.8.8.8`n
nameserver 8.8.4.4`n'

## https://technet.microsoft.com/en-us/library/hh849859.aspx
Add-Content -Path C:\Users\UserName\Desktop\test.txt -Value $text