-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Group-ObjectFast
- Loading branch information
Showing
13 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
|
||
function Group-ObjectFast | ||
{ | ||
[CmdletBinding(DefaultParameterSetName='Analysis')] | ||
param | ||
( | ||
[Parameter(Mandatory)] | ||
[string[]] | ||
$Property, | ||
|
||
[Parameter(ParameterSetName='Analysis')] | ||
[Switch] | ||
$NoElement, | ||
|
||
[Parameter(ParameterSetName='Separation')] | ||
[Switch] | ||
$AsHashtable, | ||
|
||
[Parameter(ParameterSetName='Separation')] | ||
[Switch] | ||
$AsString, | ||
|
||
[Parameter(Mandatory, ValueFromPipeline)] | ||
[object] | ||
$InputObject | ||
) | ||
|
||
begin | ||
{ | ||
# create an empty hashtable | ||
$hashtable = @{} | ||
} | ||
|
||
|
||
process | ||
{ | ||
# calculate the unique key based on the properties | ||
# submitted by the user | ||
if ($AsString -or $PSCmdlet.ParameterSetName -eq 'Analysis') | ||
{ | ||
$key = $(foreach($_ in $Property) { $InputObject.$_ }) -join ',' | ||
} | ||
else | ||
{ | ||
$key = foreach($_ in $Property) { $InputObject.$_ } | ||
} | ||
|
||
# check to see if the key is present already | ||
if ($hashtable.ContainsKey($key) -eq $false) | ||
{ | ||
# add an empty array list | ||
$hashtable[$key] = [Collections.Arraylist]@() | ||
} | ||
|
||
# add element to appropriate array list: | ||
$null = $hashtable[$key].Add($InputObject) | ||
} | ||
|
||
end | ||
{ | ||
if ($AsHashtable) | ||
{ | ||
return $hashtable | ||
} | ||
elseif ($NoElement) | ||
{ | ||
foreach($_ in $hashtable.Keys) | ||
{ | ||
[PSCustomObject]@{ | ||
Count = $hashtable[$_].Count | ||
Name = $key | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
foreach($_ in $hashtable.Keys) | ||
{ | ||
[PSCustomObject]@{ | ||
Count = $hashtable[$_].Count | ||
Name = $key | ||
Group = $hashtable[$_] | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.