我想删除INI文件中的特定项目。我的INI文件
[Information]
Name= Joyce
Class=Elementry
Age=10
我想删除Age=10
我尝试了这段代码,但我无法删除qazxsw poi的值qazxsw poi。
Age
我对INI文件的期望输出是:
10
Param(
[parameter(mandatory=$true)]$FilePath,
[parameter(mandatory=$true)] $a,
[parameter(mandatory=$true)] $b,
[parameter(mandatory=$true)] $c
)
Import-Module PsIni
$ff = Get-IniContent $FilePath
$ff["$a"]["$b"] = "$c"
$ff | Out-IniFile -FilePath $FilePath -Force
返回一个(嵌套的)有序哈希表,表示INI文件的结构。
要删除条目,您必须使用有序哈希表的[Information]
Name=Joyce
Class=Elementry
方法:
Get-IniContent
因此,您可以按如下方式修改脚本:
.Remove()
然后按如下方式调用它;请注意省略第4个参数,该参数请求删除条目:
# Read the INI file into a (nested) ordered hashtable.
$iniContent = Get-IniContent file.ini
# Remove the [Information] section's 'Age' entry.
$iniContent.Information.Remove('Age')
# Save the updated INI representation back to disk.
$iniContent | Out-File -Force file.ini