如何使用powershell编辑INI文件的值? [英] How do I edited value of INI file using powershell?

查看:826
本文介绍了如何使用powershell编辑INI文件的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个INI文件:



I have an INI file :

[Participant]
Kids=1000
Adult=200

[Gender]
Female=100
Male=200

I want to edit the value of section participant which is Kids to be 500





我的尝试:



我试过这个代码,但它返回错误





What I have tried:

I tried this code, but it return an error

Cannot index into a null array.







$input_file = Get-Content "C:\Users\testing.ini"
$input_file["Participant"]["Kids"]="500"
$input_file | Out-IniFile -Force -FilePath "C:\Users\testing.ini"

推荐答案

input_file = Get -ContentC:\ Users \ testing.ini
input_file = Get-Content "C:\Users\testing.ini"


input_file [Participant] [Kids] =500
input_file["Participant"]["Kids"]="500"


input_file | Out-IniFile -Force -FilePathC:\ Users \ testing.ini
input_file | Out-IniFile -Force -FilePath "C:\Users\testing.ini"


这篇关于如何使用powershell编辑INI文件的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆