Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Making my script faster.

$
0
0

So i've made a script that checks a CSV file for IP configuration settings and sets them on the list of corresponding machines.

the csv data fields are like this.

Machine : machine1.contoso.com
IP      : 10.1.91.101
Subnet  : 255.255.255.0
Gateway : 10.1.91.1
DNS     : 10.1.93.50
DNS2    : 10.1.22.50


my script is

$config = import-csv -path .\config.csv

$ErrorActionPreference = "SilentlyContinue"

foreach ($vm in $config.machine){

if($vm.length -ge 1){

$settings = Get-WmiObject win32_networkadapterconfiguration -computername $vm -filter "ipenabled = 'true'"
$dnsrecord = ($config.dns , $config.dns2)
$settings.setdnsserversearchorder($DNSrecord)
$settings.setgateways($config.gateway)
$settings.enablestatic($config.ip , $config.subnet)
echo $vm "complete"
}

}

This script works except for 2 issues.

The first is sometimes(randomly) it skips the setgateways command

The second is that it takes forever to finish.

any recommendations?


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>