@@ -6377,7 +6377,7 @@ $([Security.SecurityElement]::Escape($VisibilityCondition[$c]))
6377
6377
6378
6378
# If provided, will colorize all rows in a table, according to the script block.
6379
6379
# If the script block returns a value, it will be treated either as an ANSI escape sequence or up to two hexadecimal colors
6380
- [Parameter(ValueFromPipelineByPropertyName=$true )]
6380
+ [Parameter(ValueFromPipelineByPropertyName)]
6381
6381
[Alias('ColourRow')]
6382
6382
[ScriptBlock]$ColorRow,
6383
6383
@@ -6409,20 +6409,21 @@ $([Security.SecurityElement]::Escape($VisibilityCondition[$c]))
6409
6409
6410
6410
# If provided, the table view will only be used if the the typename includes this value.
6411
6411
# This is distinct from the overall typename, and can be used to have different table views for different inherited objects.
6412
- [Parameter(ValueFromPipelineByPropertyName=$true )]
6412
+ [Parameter(ValueFromPipelineByPropertyName)]
6413
6413
[string]
6414
6414
$ViewTypeName,
6415
6415
6416
6416
# If provided, the table view will only be used if the the typename is in a SelectionSet.
6417
6417
# This is distinct from the overall typename, and can be used to have different table views for different inherited objects.
6418
- [Parameter(ValueFromPipelineByPropertyName=$true )]
6418
+ [Parameter(ValueFromPipelineByPropertyName)]
6419
6419
[string]
6420
6420
$ViewSelectionSet,
6421
6421
6422
6422
# If provided, will selectively display items.
6423
- [Parameter(ValueFromPipelineByPropertyName=$true )]
6423
+ [Parameter(ValueFromPipelineByPropertyName)]
6424
6424
[ScriptBlock]
6425
- $ViewCondition)
6425
+ $ViewCondition
6426
+ )
6426
6427
6427
6428
begin {
6428
6429
$rowEntries = @()
@@ -6431,9 +6432,25 @@ $([Security.SecurityElement]::Escape($VisibilityCondition[$c]))
6431
6432
if ($_ -is [scriptblock]) { "`$(`$Script:_LastCellStyle = `$(`$__ = `$_;. {$($_)};`$_ = `$__);`$Script:_LastCellStyle)"}
6432
6433
else { "`$(`$Script:_LastCellStyle ='$($_)';`$Script:_LastCellStyle)" }
6433
6434
}
6435
+
6436
+ $myParameterNames = @(($MyInvocation.MyCommand -as [Management.Automation.CommandMetadata]).Keys) -as [string[]]
6434
6437
}
6435
6438
6436
6439
process {
6440
+ # ValueFromPipelineByPropertyName is great, but it is "sticky".
6441
+ # Parameters that have been bound aren't "unbound" until a new value is provided.
6442
+ # This means that if a parameter is not provided, it will keep the last value.
6443
+ # And that's what we call an unexpected side effect.
6444
+ # In order to avoid this, we walk over our list of parameter names
6445
+ foreach ($parameterName in $myParameterNames) {
6446
+ # if they are not in the bound parameters
6447
+ if (-not $PSBoundParameters.ContainsKey($parameterName)) {
6448
+ # we nullify them
6449
+ try { $ExecutionContext.SessionState.PSVariable.Set($parameterName, $null) }
6450
+ # and if we can't, we write a verbose message.
6451
+ catch { Write-Verbose "Could not nullify '$parameterName': $_ " }
6452
+ }
6453
+ }
6437
6454
$tableHeader = ''
6438
6455
$rowColumns =
6439
6456
@(for ($i =0; $i -lt $property.Count; $i++) {
0 commit comments