SvenIA
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)
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)
Can you post the sample .ini file to look
ASKER
applicationDirectory=C:\\P rogram 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=abcd efg1234567 890
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=abcd
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
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?
"The -replace operator only permits 2 elements on the right-hand side, not 3"
Whats wrong with Qlemo's script?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much!! It works!!