@@ -104,7 +104,7 @@ function Write-FormatTableView
104
104
105
105
# If provided, will colorize all rows in a table, according to the script block.
106
106
# If the script block returns a value, it will be treated either as an ANSI escape sequence or up to two hexadecimal colors
107
- [Parameter (ValueFromPipelineByPropertyName = $true )]
107
+ [Parameter (ValueFromPipelineByPropertyName )]
108
108
[Alias (' ColourRow' )]
109
109
[ScriptBlock ]$ColorRow ,
110
110
@@ -136,20 +136,21 @@ function Write-FormatTableView
136
136
137
137
# If provided, the table view will only be used if the the typename includes this value.
138
138
# This is distinct from the overall typename, and can be used to have different table views for different inherited objects.
139
- [Parameter (ValueFromPipelineByPropertyName = $true )]
139
+ [Parameter (ValueFromPipelineByPropertyName )]
140
140
[string ]
141
141
$ViewTypeName ,
142
142
143
143
# If provided, the table view will only be used if the the typename is in a SelectionSet.
144
144
# This is distinct from the overall typename, and can be used to have different table views for different inherited objects.
145
- [Parameter (ValueFromPipelineByPropertyName = $true )]
145
+ [Parameter (ValueFromPipelineByPropertyName )]
146
146
[string ]
147
147
$ViewSelectionSet ,
148
148
149
149
# If provided, will selectively display items.
150
- [Parameter (ValueFromPipelineByPropertyName = $true )]
150
+ [Parameter (ValueFromPipelineByPropertyName )]
151
151
[ScriptBlock ]
152
- $ViewCondition )
152
+ $ViewCondition
153
+ )
153
154
154
155
begin {
155
156
$rowEntries = @ ()
@@ -158,9 +159,25 @@ function Write-FormatTableView
158
159
if ($_ -is [scriptblock ]) { " `$ (`$ Script:_LastCellStyle = `$ (`$ __ = `$ _;. {$ ( $_ ) };`$ _ = `$ __);`$ Script:_LastCellStyle)" }
159
160
else { " `$ (`$ Script:_LastCellStyle ='$ ( $_ ) ';`$ Script:_LastCellStyle)" }
160
161
}
162
+
163
+ $myParameterNames = @ (($MyInvocation.MyCommand -as [Management.Automation.CommandMetadata ]).Keys) -as [string []]
161
164
}
162
165
163
166
process {
167
+ # ValueFromPipelineByPropertyName is great, but it is "sticky".
168
+ # Parameters that have been bound aren't "unbound" until a new value is provided.
169
+ # This means that if a parameter is not provided, it will keep the last value.
170
+ # And that's what we call an unexpected side effect.
171
+ # In order to avoid this, we walk over our list of parameter names
172
+ foreach ($parameterName in $myParameterNames ) {
173
+ # if they are not in the bound parameters
174
+ if (-not $PSBoundParameters.ContainsKey ($parameterName )) {
175
+ # we nullify them
176
+ try { $ExecutionContext.SessionState.PSVariable.Set ($parameterName , $null ) }
177
+ # and if we can't, we write a verbose message.
178
+ catch { Write-Verbose " Could not nullify '$parameterName ': $_ " }
179
+ }
180
+ }
164
181
$tableHeader = ' '
165
182
$rowColumns =
166
183
@ (for ($i = 0 ; $i -lt $property.Count ; $i ++ ) {
0 commit comments