PowerShell WMF 5 classes lacking
Votes from Connect: 3
Original Date Submitted: 5/6/2015 6:00:56 PM
Site Name: PowerShell
Feedback ID: 1307824
PowerShell are a great introduction to PowerShell, but I feel that they are lacking in a few areas currently:
- No $PSBoundParameters. With the inability to have fields (rather than properties) in PowerShell classes, and the fact that properties are always public (even with the keyword 'hidden' they can still be accessed externally to the class), it becomes impossible to determine whether a property has a value that is default because of PowerShell's coercion, or if a property has that value because the user specified that specific value. In advanced functions, this was possible using $PSBoundParameters, but such a thing does not exist in classes. Sure, we could make all of our [string]s, [boolean]s and [int]s (among others) [Nullable[string]], [Nullable[boolean]] and [Nullable[int]] but most of the people that PowerShell is targeted at do not know what System.Nullable is, which is probably the reason why $PSBoundParameters was implemented in the first place for functions.
- No $PSCmdlet - $PSCmdlet provides quite a good array of features, including but not limited to... WriteError and ThrowTerminatingException, but $PSCmdlet is not available inside a class. Sure, there is still Write-Error, but it generates a rather 'ugly' ErrorRecord that pales in comparison to $PSCmdlet.WriteError and there's also the throw keyword, but it doesn't really generate a terminating error (it can be stopped from being a terminating error by using ErrorAction Continue).
- No ability to push an object to the pipeline - While an object can be pushed to the pipeline through the return statement, there is no way to push one object at the time - yield return. It is also not possible to invoke $PSCmdlet.WriteObject() since $PSCmdlet is not present, and Write-Output gets ignored. This is probably the biggest issue I can see, as it breaks the whole concept of PowerShell's ability to process one record at the time without having to store everything in memory when using the new classes.
Product Studio item created by Connect Synchronizer due to creation of feedback ID 1307824 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=1307824).
Internal BugId: 14447