Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -IgnoreEmptySection parameter to Get-IniContent #69

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion PSIni/Functions/Get-IniContent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@

# Remove lines determined to be comments from the resulting dictionary.
[Switch]
$IgnoreComments
$IgnoreComments,

# Remove sections without any key
[Switch]
$IgnoreEmptySections
)

Begin {
Expand Down Expand Up @@ -160,6 +164,18 @@
}
}
Write-Verbose "$($MyInvocation.MyCommand.Name):: Finished Processing file: $FilePath"
if($IgnoreEmptySections){
$ToRemove = [System.Collections.ArrayList]@()
foreach($Section in $ini.Keys){
if(($ini[$Section]).Count -eq 0){
$ToRemove.Add($Section)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line produces console output with the index of the array where the item was added to (see screenshot).
prefix this line with $null = to capture (and hide) this write to stdout

image

}
}
foreach($Section in $ToRemove){
Write-Verbose "$($MyInvocation.MyCommand.Name):: Removing empty section $Section"
$ini.Remove($Section)
}
}
Write-Output $ini
}

Expand Down