[Webinar] Streamline your web hosting managementRegister Today

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

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)
0
SvenIA
Asked:
SvenIA
  • 4
  • 2
1 Solution
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Can you post the sample .ini file to look
0
 
SvenIAAuthor Commented:
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
 
SvenIAAuthor Commented:
The ip address 10.0.0.5 has to be changed every time i install the app on a cliƫnt computer.
0
SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

 
QlemoDeveloperCommented:
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
 
SvenIAAuthor Commented:
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
 
QlemoDeveloperCommented:
$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
 
SvenIAAuthor Commented:
Thanks so much!! It works!!
0

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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