[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

Scripting

Hi Experts

I have a situation in my work need to change the IP address for few windows 2003 and 2008 servers in C:\Program Files\App\opt.txt( this text file has IP address and that need be change in different IP) . the application work with IP address.
I have a servers list in the CSV or TXT file, I am looking for the PowerShell scrip and that need to execute from workstation. Script goes and changes the IP address in opt.txt in the program file.
Please help me with this scripting … much appreciate.

Thanks

0
Jey_P
Asked:
Jey_P
  • 3
  • 3
1 Solution
 
Chris DentPowerShell DeveloperCommented:
As in you need to read the current IP of the system and put it into that text file?

Chris
0
 
Jey_PAuthor Commented:

thanks for your responce, no need to read the IP  and need to change the different IP .

There are one application server in our company and client installed every servers , the client will hold the application server IP in txt file located in C:\.  We are in situation to move the new VLAN and new IP. So instated of login each server and modify the IP, I am looking for the power shell command to modify the IP address number of servers in one shot. Is it possible to do it in PowerShell?  Sorry for the confusion.
0
 
Chris DentPowerShell DeveloperCommented:
Sure, it's not so hard. First, we get the right network interface. Does anything have more than one?

Then our code looks something like this:
$Network = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IPEnabled=$True"
$Network.EnableStatic("New.IP.Address", "New.Subnet.Mask")
$Network.SetGateways("New.IP.Gateway")

Open in new window

Of course, it'll be a bit tricky doing this over the network, you'll lose connection the moment you change IP. But we can work with that if we make sure whatever script we run is running on the host machine, not over the network.

Will subnet mask and gateway be the same in all cases? And do you need to change any of the other details?

Chris
0
New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

 
Jey_PAuthor Commented:
Thanks Chris.

we not going to change the host IP  . I want to replace the old IP to New IP that located in the C:\programfile\.txt .
0
 
Jey_PAuthor Commented:
Can you please modify the script bit and help me to complete this task. Only I need to change the IP for application that installed in the txt file located (c:\program files\app\txt.), I am not change the host IP.
I have numerous hosts have same above situation to change the IP. (the IP in CSV format).
0
 
Chris DentPowerShell DeveloperCommented:
Sorry, lost track.

Perhaps we could do it like this.
$OldIP = "1\.2\.3\.4"
$NewIP = "2.3.4.5"

# Run through a list of servers
Get-Content YourList.txt | ForEach-Object {
  $File = Get-Content "\\$_\Program Files\App\opt.txt"
  $File -Replace $OldIP, $NewIP
  $File | Set-Content "\\$_\Program Files\App\opt.txt"
}

Open in new window

$OldIP above is a regular expression, that's why each of the dots has a \ before it. That format should remain, but the IP should be updated to reflect the one we're swapping out.

Does that do what you need?

Chris
0

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now