Roger Hall Roger Hall - 3 months ago 36
Ini Question

Get-IniContent Help Getting Specific Sections with Wildcards

I have multiple INI files that I have to update regularly as new lines are being added in our call center. I can use the get-inicontent script to get the values I'm trying to compare however The ID section sometimes has spaces and sometimes doesn't also and probably the biggest trouble I'm having is scaling. Each INI can have multiple sections labeled the same thing but with a number at the end. I need the ID for each ACD section. See below for an example of my file and what I use to get the value for one ACD. The below script returns each value but it requires individual query for each and note the spaces for those that have tabs. I'd like to figure out a way to return all ACD ID results that ignores the extra spaces. Any help would be greatly appreciated.

INI File:

PS Script:
$FileContents = Get-IniContent "C:\Temp\ScriptTest\CTISetupTest.ini"
$FileContents.ACD2.' ID'
$FileContents.ACD3.' ID'

Expected Results would be:


Answer Source

Just loop over the keys starting with ACD and then loop over the subkeys ending in ID.

$INI = Get-IniContent 'C:\Temp\ScriptTest\CTISetupTest.ini'
$ACDKeys = ($INI).keys | Where-Object {$_ -like 'acd*'}
foreach ($ACDKey in $ACDKeys) {
    $IDKeys = $INI[$ACDKey].Keys | Where-Object {$_ -like '*ID'}
    foreach ($IDKey in $IDKeys){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download