-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGet-AllParametersWithAValue.ps1
38 lines (35 loc) · 1.09 KB
/
Get-AllParametersWithAValue.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
Function Get-AllParametersWithAValue
{
[cmdletbinding()]
param
(
$BoundParameters #$PSBoundParameters
,
$AllParameters #$MyInvocation.MyCommand.Parameters
,
[switch]$IncludeCommon
,
$Scope = 1
)
$getAllParameterParams = @{
BoundParameters = $BoundParameters
AllParameters = $AllParameters
}
if ($IncludeCommon -eq $true) {$getAllParametersParams.IncludeCommon = $true}
$AllParameterKeys = Get-AllParameter @getAllParameterParams
$AllParametersWithAValue = @(
foreach ($k in $AllParameterKeys)
{
try
{
Get-Variable -Name $k -Scope $Scope -ErrorAction Stop | Where-Object -FilterScript {($null -ne $_.Value -and -not [string]::IsNullOrWhiteSpace($_.Value)) -or $BoundParameters.ContainsKey($k)}
}
catch
{
#don't care if a particular variable is not found
Write-Verbose -Message "$k was not found"
}
}
)
$AllParametersWithAValue
}