Reputation: 45
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:
[ACD1]
ID=1001
[ACD2]
ID=1002
[ACD3]
ID=1003
[Extension1]
ID=50001
[Extension2]
ID=50002
PS Script:
$FileContents = Get-IniContent "C:\Temp\ScriptTest\CTISetupTest.ini"
$FileContents.ACD1.ID
$FileContents.ACD2.' ID'
$FileContents.ACD3.' ID'
Expected Results would be:
1001
1002
1003
Upvotes: 0
Views: 798
Reputation: 10044
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){
$INI[$ACDKey][$IDKey]
}
}
Upvotes: 1