Solved

Replace a value in an .ini file using powershell

Posted on 2014-02-04
7
3,584 Views
Last Modified: 2014-02-04
Hi Everyone,

I'm pretty much new to powershell. What i want to achieve is the following;

I have an .ini file that is used to perform a silent install of some application. I need to install the application on a lot of different workstations. The .ini file has an ip address defined.

I need a powershell script that changes the ip address in the .ini file. When the script runs, i want a pop-up box that asks for the ip address. When i type for examaple 10.0.0.1, i want that ip address to be added or changed on a specific place in the .ini file.

Is that possible? (hope i made myself clear on this one)
0
Comment
Question by:SvenIA
  • 4
  • 2
7 Comments
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39832174
Can you post the sample .ini file to look
0
 
LVL 7

Author Comment

by:SvenIA
ID: 39832212
applicationDirectory=C:\\Program Files\\APC\\PowerChute
ACCEPT_EULA=yes
INSTALL_JAVA=SYSTEM
REGISTER_WITH_NMC=yes
MODE=single
IP_1=10.0.0.5
IP_1_Outlet=1
PORT=80
PROTOCOL=http
ACCEPTCERTS=YES
USERNAME=Admin            
PASSWORD=Admin
AUTHENTICATION_PHRASE=abcdefg1234567890
0
 
LVL 7

Author Comment

by:SvenIA
ID: 39832215
The ip address 10.0.0.5 has to be changed every time i install the app on a cliënt computer.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 69

Expert Comment

by:Qlemo
ID: 39832247
This should be all you need:
$ip = Read-Host "Enter IP address to store in .INI:"

(Get-Content C:\temp\File.ini) -replace 'IP_1=.*', 'IP_1='+$ip | Set-Content c:\temp\File.Ini

Open in new window

0
 
LVL 7

Author Comment

by:SvenIA
ID: 39832324
Thanks! It shows an error;

"The -replace operator only permits 2 elements on the right-hand side, not 3"

Whats wrong with Qlemo's script?
0
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39832364
$ip = Read-Host "Enter IP address to store in .INI:"

(Get-Content C:\temp\File.ini) -replace 'IP_1=.*', ('IP_1='+$ip) | Set-Content c:\temp\File.Ini

Open in new window

0
 
LVL 7

Author Closing Comment

by:SvenIA
ID: 39832385
Thanks so much!! It works!!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Set OWA language and time zone in Exchange for individuals, all users or per database.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question