I have a txt file that looks like this


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("", 1)
$wmi.EnableStatic("?????", "")

any help on that?

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

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

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.


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.