forked from brianary/scripts
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Add-Counter.ps1
46 lines (38 loc) · 1.23 KB
/
Add-Counter.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
<#
.SYNOPSIS
Adds an incrementing integer property to each pipeline object.
.DESCRIPTION
If you want to add a quick index property to objects in a pipeline, this does that.
.INPUTS
System.Management.Automation.PSObject item to add an index property to.
.OUTPUTS
System.Management.Automation.PSObject with the added index property.
.FUNCTIONALITY
PowerShell
.LINK
Add-Member
.EXAMPLE
Get-PSProvider |Add-Counter Position |select Name,Position
Name Position
---- --------
Registry 1
Alias 2
Environment 3
FileSystem 4
Function 5
Variable 6
Certificate 7
#>
#Requires -Version 3
[CmdletBinding()][OutputType([psobject])] Param(
# The name of the property to add.
[Parameter(Position=0)][string] $PropertyName = 'Counter',
# The starting number to count from.
[Parameter(Position=1)][int] $InitialValue = 1,
# The object to add the property to.
[Parameter(Mandatory=$true,ValueFromPipeline=$true)][psobject] $InputObject,
# Overwrites a property if one with the same name already exists.
[switch] $Force
)
Begin { $i = $InitialValue }
Process { Add-Member $PropertyName ($i++) -InputObject $InputObject -PassThru -Force:$Force }