-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathethical_cloning-ex.ps1
87 lines (72 loc) · 2.32 KB
/
ethical_cloning-ex.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# from: <https://discord.com/channels/180528040881815552/1094669741039296632/1096251223914590269>
filter Expand-Property {
<#
.SYNOPSIS
Expands an array property, creating a duplicate object for each value
#>
param(
# The name of a property on the input object, that has more than one value
[Alias("Property")]
[string]$Name,
# The input object to duplicated
[Parameter(ValueFromPipeline)]
$InputObject
)
foreach ($Value in $InputObject.$Name) {
$InputObject | Select-Object *, @{ Name = $Name; Expr = { $Value } } -Exclude $Name
}
}
function Group-Property {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true)]
[psobject]
${InputObject},
[Parameter(Position = 0)]
[string]
${Name},
[string]
${Culture},
[switch]
${CaseSensitive}
)
begin {
try {
$outBuffer = $null
$null = $PSBoundParameters.Remove("Name")
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) {
$PSBoundParameters['OutBuffer'] = 1
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Group-Object', [System.Management.Automation.CommandTypes]::Cmdlet)
} catch {
throw
}
}
process {
try {
if (!$steppablePipeline) {
$PSBoundParameters["Property"] = $InputObject.PSObject.Properties.Name.Where{ $_ -ne $Name }
$null = $PSBoundParameters.Remove("InputObject")
Write-Verbose "Group by $($PSBoundParameters["Property"] -join ', ')"
$scriptCmd = { & $wrappedCmd @PSBoundParameters | ForEach-Object { $_.Group[0].$Name = $_.Group.$Name; $_.Group[0] } }
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
$steppablePipeline.Begin($PSCmdlet)
}
$steppablePipeline.Process($_)
} catch {
throw
}
}
end {
try {
$steppablePipeline.End()
} catch {
throw
}
}
clean {
if ($null -ne $steppablePipeline) {
$steppablePipeline.Clean()
}
}
}