Solved

Replace a value in an .ini file using powershell

Posted on 2014-02-04
7
3,391 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 18

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
[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

 
LVL 68

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 68

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
This article will help you understand what HashTables are and how to use them in PowerShell.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now