?
Solved

Replace a value in an .ini file using powershell

Posted on 2014-02-04
7
Medium Priority
?
4,165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 70

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 70

Accepted Solution

by:
Qlemo earned 2000 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

771 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