1

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?

Thanks

2 Answers 2

1

Here is the function I use :

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 {}
}

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"]

gives

"Bip PC"
Sign up to request clarification or add additional context in comments.

Comments

0

.ini files are normally key = value pairs, that are easily convertible to a hash table using ConvertFrom-StringData

Read a properties file in powershell

From there it's just a matter of reading the value of the hash Program_Version key from the hash table.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.