Add ValidateNotNullOrEmpty attribute to the -Property of Format-Table/List/Custom#26552
Merged
daxian-dbw merged 2 commits intoPowerShell:masterfrom Jan 12, 2026
Merged
Add ValidateNotNullOrEmpty attribute to the -Property of Format-Table/List/Custom#26552daxian-dbw merged 2 commits intoPowerShell:masterfrom
ValidateNotNullOrEmpty attribute to the -Property of Format-Table/List/Custom#26552daxian-dbw merged 2 commits intoPowerShell:masterfrom
Conversation
…able/List/Custom`
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #26543 by adding the ValidateNotNullOrEmpty attribute to the -Property parameter of Format-Table, Format-List, and Format-Custom cmdlets to prevent null reference exceptions when empty arrays or null values are passed.
Key Changes:
- Added validation attribute to prevent null/empty Property values in Format-Table, Format-List, and Format-Custom
- Added comprehensive test coverage for all three cmdlets verifying both null and empty array scenarios throw appropriate validation errors
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommand.cs | Added ValidateNotNullOrEmpty attribute to the Property parameter in OuterFormatTableAndListBase class, which is inherited by Format-Table and Format-List |
| src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-object/Format-Object.cs | Added ValidateNotNullOrEmpty attribute to the Property parameter in FormatCustomCommand class |
| test/powershell/engine/Formatting/BugFix.Tests.ps1 | Added test cases to verify that Format-Table, Format-List, and Format-Custom properly throw ParameterArgumentValidationError when Property is passed null or empty array |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
SeeminglyScience
approved these changes
Jan 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Fix #26543
Add the
ValidateNotNullOrEmptyattribute to the parameter-PropertyforFormat-Table,Format-List, andFormat-Custom.This is to fix the null reference exception when using an empty array as the argument for
-Property.Breaking Change
It's a breaking change as today you can use
$nullas the argument forFormat-List/Table/Custom, which behaves the same as-Propertyis not specified. By adding theValidateNotNullOrEmptyattribute,-Property $nullwill fail. But this may fall in the bucket 3 (grey area) though.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header