-
Notifications
You must be signed in to change notification settings - Fork 0
/
Where-Value.ps1
71 lines (59 loc) · 1.79 KB
/
Where-Value.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
<#
.Synopsis
The function returns objects which have got input value in any properties.
.DESCRIPTION
The function returns objects which have got input value in any properties. The function
adds to the original object the property "ValueInProperty".
There it saves properties` names in whose value was found.
.EXAMPLE
przyklad_1
.EXAMPLE
przyklad_2
.NOTES
Author: autor
Link: akademiapowershell.pl
Date: 03-10-2019
Version: version
eywords: keywords
Notes:
Changelog:
#>
Function Where-Value
{
[Cmdletbinding()]
Param
(
[parameter(ValueFromPipeline)]
$InputObject,
[parameter(Mandatory)]
$Value
)
Process
{
$PSItem.PSObject.Properties | ForEach-Object {
# Value search
if ($_.Value -match $value)
{
# Adding to the variable name of property`
[array]$ValueInProperty += $_.Name
}
}
if ([array]$ValueInProperty)
{
# Adding a new property
#$PSItem | Add-Member -MemberType NoteProperty -Name "ValueInProperty" -Value $ValueInProperty
#Remove-Variable -Name ValueInProperty
Write-Output $PSItem
}
}
End
{
Write-Verbose "The value $Value contains property: $ValueInProperty"
}
}
<#
Ciekawy wpis. Dodam od siebie, że pierwsze zadanie najłatwiej wykonać: Get-Service | Select *Name* Drugie faktycznie nie należy do tych trywialnych.
Co do 'Stopped' jako true, wydaje mi się, że to wynika, z niejawnej konwersji liczbowej wartości tego statusu (1) do typu [Bool]
[System.ServiceProcess.ServiceControllerStatus]::Stopped.value__ -eq $true
[System.ServiceProcess.ServiceControllerStatus]::Running.value__ -eq $false
#>