Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.160
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.17763.0
Hi guys, A slightly annoying issue with powershell is that it does not recognize the object script blocks with an open brace on a newline. I am in the habit (rightly or wrongly) of placing braces on a newline (except under these situations) and occasionally I forget.
PSS does not see this as an error and the script packages up ok but when you go to run it you get that awesome blocking user input request
cmdlet ForEach-Object at command pipeline position 1
Supply values for the following parameters:
eg.
This is good...
(1..3) | ?{ $_ -eq 1 }
This is NOT...
(1..3) | ?
{
$_ -eq 1
}
Maybe a future PS build will handle this but in the meantime would it be possible for PSS to detect this situation as an ERROR?
Thanks
Error object blocks with open brace on newline
Forum rules
Do not post any licensing information in this forum.
Do not post any licensing information in this forum.
Re: Error object blocks with open brace on newline
Please try the latest service build of PowerShell Studio (v165). It should resolve this issue.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Error object blocks with open brace on newline
Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.165
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.17763.0
Hi David,
That would have been amazing (and coincidental) had it resolved the issue, but it did not.
I pasted this into a new script and run through the PSS editor and it raised the smdlet where-object user input dialog and the editor did not indicate this was a problem by display a red bang.
(1 .. 3) | Where-Object
{
$_ -eq 1
}
Build: v5.6.165
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.17763.0
Hi David,
That would have been amazing (and coincidental) had it resolved the issue, but it did not.
I pasted this into a new script and run through the PSS editor and it raised the smdlet where-object user input dialog and the editor did not indicate this was a problem by display a red bang.
(1 .. 3) | Where-Object
{
$_ -eq 1
}
Re: Error object blocks with open brace on newline
My apologies, I misunderstood the request. I thought you were reporting a formatting issue where PowerShell Studio was placing the opening bracket on a new line.
As for errors, it is PowerShell engine that reports the syntax errors. Even though your intention was for the script block to be part of the Where-Object command, according to PowerShell, this is a valid statement and there is nothing syntactically wrong with it.
As for errors, it is PowerShell engine that reports the syntax errors. Even though your intention was for the script block to be part of the Where-Object command, according to PowerShell, this is a valid statement and there is nothing syntactically wrong with it.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Error object blocks with open brace on newline
David,
No problem and understand what you are saying. Yes, syntax wise, it's fine, but if your intention is to have a non blocking script to run that does not require user input then this unexpected behavior can be very frustrating.
Maybe if I try a new approach, rather than PSS reporting this as an error, perhaps it could raise a warning. Something along the lines of...
"Placing a script block following an object statement on a newline will cause Powershell to request user input. Are you sure that you wish to do this?".
...or something along those lines. I know it's not really the responsibility of PSS but it would be a nice feature (perhaps an optional feature)
Thanks
No problem and understand what you are saying. Yes, syntax wise, it's fine, but if your intention is to have a non blocking script to run that does not require user input then this unexpected behavior can be very frustrating.
Maybe if I try a new approach, rather than PSS reporting this as an error, perhaps it could raise a warning. Something along the lines of...
"Placing a script block following an object statement on a newline will cause Powershell to request user input. Are you sure that you wish to do this?".
...or something along those lines. I know it's not really the responsibility of PSS but it would be a nice feature (perhaps an optional feature)
Thanks
Re: Error object blocks with open brace on newline
I understand and thank you for the suggestion. I wonder if this would make more sense as a PSScriptAnalyzer rule.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Error object blocks with open brace on newline
Hmmmm, yes, that seems like a logical place. Thanks for the feedback David.
Cheers
Cheers