Powershell netsh automatically run script

Is there a way to input text to notepad stating an IP Address, Subnet mask and Gateway and then running a powershell script that would execute the following netsh interface ipv4> set address name="Wireless Network Connection" source=static addr=192.xxx.x.xx mask=255.255.0.0 gateway=xxx.xxx.x.x gwmetric=0

At the moment I just type that manually in a Powershell terminal or cmd and it works (changes what i want changed) but i want to be able to just edit a notepad file and exute a batch file that would automatically do it..

i am pretty new to powershell and scripting but if someone can point me in the right direction it would be hugely appreciated.

Thanks.

Answers


There are many ways for you to do this. Here is one:

ip_properties.txt contents:

192.168.1.15,255.255.255.0,192.168.1.1

powershell script contents:

$properties = (Get-Content ip_properties.txt) -split ','
Invoke-Expression "netsh interface ip set address name='Wireless Network Connection' source=static addr=$($properties[0]) mask=$($properties[1]) gateway=$($properties[2]) gwmetric=0"

Essentially you're supplying your interface parameters in a comma separated format, splitting the those properties into an array and then using the array elements as inputs to the netsh command


Need Your Help

Using sql function min() in php loop

php sql min minimum

I have to output some products from table 'products', along with the lowest price from the table 'product_licenses', which is the only column I need from that table in this query.

How to read iCollection data in repository pattern - ASP.NET- MVC Entity Framework

c# asp.net-mvc entity-framework repository-pattern unit-of-work

I am using repository pattern and unit of work in my ASP.NET-MVC application. I have generic repository for CRUD operation and service class between Unit of Work and controller class; meaning contr...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.