1

I have a txt file that looks like this

PC1 192.168.0.2  
PC2 192.168.0.3  
PC3 192.168.0.4

I would like to change computers ip addresses based on that list, so it will fill up the computer name and the ip address and process them all without manually changing the values, and I'm having issues getting this to work "still learning powershell"

$wmi = Get-WmiObject -ComputerName ??? win32_networkadapterconfiguration -filter "ipenabled = 'true'"

$wmi.SetGateways("192.168.0.1", 1)
$wmi.EnableStatic("?????", "255.255.255.0")

any help on that?

  • DHCP reservations? – PnP Mar 28 '15 at 21:06
3

If your txt file is just a space-separated list of [computername] [ip-address], you can use the Import-Csv cmdlet:

$Computers = Import-Csv -Path C:\file.txt -Delimiter " " -Header Name,IP

foreach($Computer in $Computers){
    # Query $Computer.Name
    # Assign $Computer.IP as the static address
}
| improve this answer | |
4

Mathias' answer is perfectly suited for the question as asked. A much better, more maintainable way to accomplish the goal, however, is to use a DHCP server with reservations.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.