Properties and Methods Expansion

Use this forum to ask questions after your subscription maintenance expires or before you buy. Need information on licensing or pricing? Questions about a trial version? This is the right place for you. No scripting questions, please.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
larrybtagao
Posts: 9
Last visit: Tue Jul 12, 2022 8:29 am

Properties and Methods Expansion

Post by larrybtagao »

I've been wondering if PS Studio has properties/methods "expansion" in intellisense for cmdlets like ISESteroids has. This feature reveals the properties and methods using dot notation
As an example, typing (get-process). reveals all the properties and methods for a process object. I've been looking everywhere and couldn't find this on PS Studio. This would be very handy feature to have, trying to decide between ISESteroids and PSStudio and I generally like PSStudio better but I'll have to reconsider if it doesn't have it, even the free VS code has that feature.
LBTagao
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Properties and Methods Expansion

Post by davidc »

Yes, PowerShell Studio provides PrimalSense information for Cmdlets.
Cmdlet PrimalSense.png
Cmdlet PrimalSense.png (23.15 KiB) Viewed 33073 times
If you want the state of a particular variable, you can set a breakpoint at the appropriate line and run the Debugger (F5). When the editor hits a breakpoint, it will store the session information to provide PrimalSense. Refer to the following article for more details:

https://www.sapien.com/blog/2017/07/20/ ... -v5-4-142/

Note: PowerShell Studio always resets the runspace to ensure your script doesn't have dependencies on a modified runspace / variable. Nor does it load profiles to ensure that you can run the script elsewhere and not have local dependencies.
David
SAPIEN Technologies, Inc.
User avatar
larrybtagao
Posts: 9
Last visit: Tue Jul 12, 2022 8:29 am

Re: Properties and Methods Expansion

Post by larrybtagao »

Hi David,

As you can see yourself from your screenshot, the primalsense provides only the methods for a generic PSObject (some are not even applicable like the 'getEnumerator' which only works for hashtable), not the methods and properties for an instance of a specific object e.g System.Diagnostics.Process. I'm looking for the same instance members you'd get when you pipe an object into 'get-member'. The bare ISE and VS Code has this (attached screenshots).

I know how to use the debug function. I was just wondering if this 'feature' can be enabled on PSStudio so that I can check what members an object instance has from the script pane without having to go to console and do 'get-something | get-member' to view their properties. This is also useful if I'm piping an object to 'select-object' and I don't know exactly the members' name for that object
Attachments
PSISE_01.jpg
PSISE_01.jpg (32.81 KiB) Viewed 33013 times
PSISE.JPG
PSISE.JPG (33.98 KiB) Viewed 33016 times
VSCode.JPG
VSCode.JPG (33.17 KiB) Viewed 33016 times
LBTagao
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Properties and Methods Expansion

Post by davidc »

This really boils down to a philosophical difference and the different between writing a script and working in the console.

Run the following in the ISE and you will get a similar result as PowerShell Studio:
Get Process in Variable ISE.png
Get Process in Variable ISE.png (16.61 KiB) Viewed 32937 times
Would you agree that they are the same thing? If so, then why does the ISE produce two different results?

Since the command hasn’t ran, the ISE will present all the possibilities at once. Meaning, it merges all the possible types the command can return and product a list of all the properties and methods from all the types at once.
This can be confusing and can result in an error prone script. If you do not know the exact type and properties, you could potentially reference the property of one type, yet when the script runs, it can return a different type that doesn’t contain that property.

Referencing the member of the contents of an array (V3 feature), can also lead to error prone scripts.
Let’s look at the following example:
  1. $process = Get-Process -Name Notepad
  2. $nameOfProcess = $process.Name
  3. $nameOfProcess.GetType().Name
  4. $nameOfProcess
Looking at the script, you might assume that $nameOfProcess a string containing “Notepad”. But you would be incorrect if there are multiple instances of Notepad running.

Single Instance Output:

Code: Select all

String
Notepad
Vs Multiple Instance Output:

Code: Select all

Object[]
notepad
notepad
As you can see, you are dealing with two different types. One is a single string and the other an array. If the user is not aware of this, they can run into unforeseen problems in a script vs running individual commands in a console.
Note: If you are using PowerShell V2, the multiple instance example would have produced an error.
PowerShell does a lot of conversions under the hood to help make it easier to use in the console, but the side effect is that scripts are more confusing and less predictable.

When writing a script, the types should be clearly defined to help with clarity and readability. When writing a script, we should think about the next person who need to read the script and figure out what is happening. I know we don’t always do this, but that is why it is considered a best practice to avoid aliases (especially custom alias that may only exist on your machine).
David
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Properties and Methods Expansion

Post by davidc »

As for the custom PowerShell properties, it is also a side effect of having the editor separated from the PowerShell instance. But I brought this up with the dev team and we will address it in an upcoming build.

I thank you for your honest feedback. Feedback like this helps us create a better product.
David
SAPIEN Technologies, Inc.
User avatar
larrybtagao
Posts: 9
Last visit: Tue Jul 12, 2022 8:29 am

Re: Properties and Methods Expansion

Post by larrybtagao »

Hi David,

For the benefits of others reading this forum, a trick that I use to determine the type of each element in an array if 'GetType()' returns an object array is to pipe it to 'get-member'. It tells you the typename of each element in the array. You can have an an int and string in the array and 'get-member' tells you that also.
ObjectType.JPG
ObjectType.JPG (18.01 KiB) Viewed 32855 times
Thanks. Do you have a timeline on when the new build is coming out?

Regards,
Larry
LBTagao
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Properties and Methods Expansion

Post by davidc »

I can't provide a exact timeline, but we usually release a new build for PowerShell Studio every month.
David
SAPIEN Technologies, Inc.
User avatar
larrybtagao
Posts: 9
Last visit: Tue Jul 12, 2022 8:29 am

Re: Properties and Methods Expansion

Post by larrybtagao »

Hi David - Was just wondering, is the build for April out yet?
LBTagao
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Properties and Methods Expansion

Post by davidc »

The build has not been released yet. FYI, we are still working on the additional type information and it will not be included in this next build.
David
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Properties and Methods Expansion

Post by davidc »

The build is now available.
David
SAPIEN Technologies, Inc.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.