Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Prompting For Variables to Set Network Information

$
0
0

Hi Folks,

 

I am new to Powershell but am attempting to learn on the fly. I am tasked with creating a script that will prompt you for the Static IP address, subnet mask, default gateway and 2 dns servers. I have tried multiple different commands to set these variables. If I don't use Read-Host and enter the static addresses in the script itself, it works. As soon as I make the variables input questions, it fails to set the IP address, subnet mask and gateway. Anyone with more experience be able to tell me where I'm going wrong at? Thanks in advance,

-Tom

 

$IP = Read-Host -Prompt $("Enter The IP Address")
$SM = Read-Host -Prompt $("Enter The Subnet Mask")
$DG = Read-Host -Prompt $("Enter your Default Gateway")
$static = ($IP,$SM,$DG)
netsh interface ip set address "Local Area Connection" static $static
$DNS1= Read-Host "Enter your Primary DNS Server Address"
$DNS2= Read-Host "Enter your Secondary DNS Server Address"
$dnsserver= $DNS1,$DNS2
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=7" | Invoke-WmiMethod -Name SetDNSServerSearchOrder -ArgumentList (,$dnsserver)

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles