【发布时间】:2019-06-06 06:50:33
【问题描述】:
我想读取我的 INI 文件的特定项目,我的 INI 文件部分中有 5 个项目,我想读取 4 个项目,除了第 3 个项目。
我已经尝试读取所有项目,但是我找不到如何指定我要读取的项目的方法,我读取的文件格式是这样的:
名称 值 AA 12 BB 13 抄送 14 15 天 EE 16我使用这个命令来执行它。
File1.ps1 Read-File -FilePath C:\Users\Data.ini -a_section Code -store C:\Users\
function Read-File {
Param(
[Parameter(Mandatory=$true)]$FilePath,
[Parameter(Mandatory=$true)]$a_section,
[Parameter(Mandatory=$true)]$store
)
$input_file = $FilePath
$ini_file = @{}
Get-Content $input_file | ForEach-Object {
$_.Trim()
} | Where-Object {
$_ -notmatch '^(;|$)'
} | ForEach-Object {
if ($_ -match '^\[.*\]$') {
$section = $_ -replace '\[|\]'
$ini_file[$section] = @{}
} else {
$key, $value = $_ -split '\s*=\s*', 2
$ini_file[$section][$key] = $value
}
}
$Path_Store = $store
$Get_Reg = $ini_file.($a_section)
$Output = $Get_Reg | Out-File $Path_Store\Out_Test
}
$cmd, $params = $args
& $cmd @params
我的预期结果,我有一个这样的输出文件
AA=12 BB=13 DD=15 EE=16我的 INI 文件如下所示:
[姓名] 1=乔 2=恩典 [代码] AA=12 BB=13 抄送=14 DD=15 EE=16【问题讨论】:
-
请不要移动目标。如果您有后续问题:发布新问题。
标签: powershell parameters arguments