从ini文件PowerShell中捕获数据 [英] capture data from ini file PowerShell
问题描述
我想解析一个ini文件并从Section中捕获数据.基本上,我试图捕获安装在1000多个服务器上的AV的版本. ini文件包含"Program_Version".此变量包含版本号.如果我使用Program_Version =进行搜索,我会直接在短语"="后找到包含版本号的短语.像8.0、10.6等
I would like to parse an ini file and capture data from a Section. Basically I am trying to capture the version of an AV installed on 1000+ Servers. the ini file contains "Program_Version". This variable contains the version no. If I search using Program_Version=, I directly find the phrase after the "=" sign it contains the version no. Like 8.0, 10.6 etc
有人可以指导我如何实现这一目标吗?
Can some one please guide me on how to achieve this?
谢谢
推荐答案
这是我使用的功能:
function Parse-IniFile
{
[CmdletBinding()]
Param
(
[Parameter(mandatory=$true,ValueFromPipeline=$true)]
[Alias("Fichier")]
[string]$fic
)
begin {}
Process
{
$ini = @{}
switch -regex -file $fic
{
"^\[(.+)\]$"
{
$section = $matches[1]
$ini[$section] = @{}
}
"(.+)=(.+)"
{
$name,$value = $matches[1..2]
$ini[$section][$name] = $value
}
}
return $ini
}
end {}
}
从"C:\ Windows \ System32 \ DriverStore \ FileRepository"目录树中获得一个INI文件.
given an INI file from "C:\Windows\System32\DriverStore\FileRepository" directory tree.
$p = Parse-IniFile "C:\Windows\System32\DriverStore\FileRepository\adihdaud.inf_amd64_neutral_66552f06054bc4ee\Mixer.ini"
$p["FRENCH"]["KSPINNAME_ADI_ALT_PCBEEP_SOURCE"]
给予
"Bip PC"
这篇关于从ini文件PowerShell中捕获数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!