Link to home
Start Free TrialLog in
Avatar of SvenIA
SvenIAFlag for Netherlands

asked on

Replace a value in an .ini file using powershell

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)
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you post the sample .ini file to look
Avatar of SvenIA

ASKER

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
Avatar of SvenIA

ASKER

The ip address 10.0.0.5 has to be changed every time i install the app on a cliënt computer.
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

Avatar of SvenIA

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SvenIA

ASKER

Thanks so much!! It works!!