forked from jdhitsolutions/PSScriptTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-MyCounter.ps1
More file actions
80 lines (64 loc) · 2.68 KB
/
Get-MyCounter.ps1
File metadata and controls
80 lines (64 loc) · 2.68 KB
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
#Requires -Module Microsoft.PowerShell.Diagnostics
#don't load this function if running Linux or Mac because they don't have the
#required Microsoft.PowerShell.Diagnostics module
if ($IsWindows -OR ($PSEdition -eq 'Desktop')) {
Class myCounter {
[string]$Computername
[string]$Category
[string]$Counter
[string]$Instance
[double]$Value #cooked value
[datetime]$Timestamp
myCounter ([Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSample]$CounterSample) {
$this.Computername = $countersample.path.split("\")[2].toUpper()
$this.Counter = $countersample.path.split("\")[-1]
$this.Category = $countersample.path.split("\")[-2]
$this.Instance = $countersample.InstanceName
$this.Value = $countersample.CookedValue
$this.Timestamp = $countersample.Timestamp
}
}
# RemoteRegistry service must be running to query remote computers and you need to have admin access
Function Get-MyCounter {
[CmdletBinding()]
[OutputType("myCounter")]
Param(
[Parameter(ParameterSetName = 'GetCounterSet', Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[AllowEmptyCollection()]
[string[]]$Counter,
[Parameter(ParameterSetName = 'GetCounterSet')]
[ValidateRange(1, 2147483647)]
[int]$SampleInterval,
[Parameter(ParameterSetName = 'GetCounterSet')]
[ValidateRange(1, 9223372036854775807)]
[long]$MaxSamples,
[Parameter(ParameterSetName = 'GetCounterSet')]
[switch]$Continuous,
[Alias('Cn')]
[ValidateNotNull()]
[AllowEmptyCollection()]
[string[]]$ComputerName
)
Begin {
Write-Verbose "[BEGIN ] Starting $($MyInvocation.Mycommand)"
} #begin
Process {
if ($isLinux -OR $IsMacOS) {
#this should never be needed
Write-Warning "This command requires a Windows platform."
}
else {
Write-Verbose "[PROCESS] Using parameter set $($PSCmdlet.ParameterSetName) with these bound parameters"
Write-Verbose ($PSBoundParameters | Out-String)
Get-Counter @PSBoundParameters | Select-Object -ExpandProperty Countersamples |
ForEach-Object { [mycounter]::new($_) }
}
} #process
End {
Write-Verbose "[END ] Ending $($MyInvocation.Mycommand)"
} #end
} #close function Get-MyCounter
}
else {
Write-Warning "This command requires a Windows platform."
}