Properties and Methods Expansion

Use this forum to ask questions 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.
User avatar
larrybtagao
Posts: 7
Joined: Mon Aug 10, 2015 9:19 pm

Properties and Methods Expansion

Post by larrybtagao » Tue Mar 20, 2018 2:01 am

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.

User avatar
davidc
Posts: 5388
Joined: Thu Aug 18, 2011 4:56 am

Re: Properties and Methods Expansion

Post by davidc » Tue Mar 20, 2018 9:51 am

Yes, PowerShell Studio provides PrimalSense information for Cmdlets.
Cmdlet PrimalSense.png
Cmdlet PrimalSense.png (23.15 KiB) Viewed 12200 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: 7
Joined: Mon Aug 10, 2015 9:19 pm

Re: Properties and Methods Expansion

Post by larrybtagao » Tue Mar 20, 2018 9:16 pm

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 12140 times
PSISE.JPG
PSISE.JPG (33.98 KiB) Viewed 12143 times
VSCode.JPG
VSCode.JPG (33.17 KiB) Viewed 12143 times

User avatar
davidc
Posts: 5388
Joined: Thu Aug 18, 2011 4:56 am

Re: Properties and Methods Expansion

Post by davidc » Wed Mar 21, 2018 11:16 am

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 12064 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.  
  3. $nameOfProcess = $process.Name
  4.  
  5. $nameOfProcess.GetType().Name
  6.  
  7. $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: 5388
Joined: Thu Aug 18, 2011 4:56 am

Re: Properties and Methods Expansion

Post by davidc » Wed Mar 21, 2018 11:20 am

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: 7
Joined: Mon Aug 10, 2015 9:19 pm

Re: Properties and Methods Expansion

Post by larrybtagao » Wed Mar 21, 2018 10:43 pm

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 11982 times
Thanks. Do you have a timeline on when the new build is coming out?

Regards,
Larry

User avatar
davidc
Posts: 5388
Joined: Thu Aug 18, 2011 4:56 am

Re: Properties and Methods Expansion

Post by davidc » Thu Mar 22, 2018 8:16 am

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: 7
Joined: Mon Aug 10, 2015 9:19 pm

Re: Properties and Methods Expansion

Post by larrybtagao » Mon Apr 16, 2018 7:00 pm

Hi David - Was just wondering, is the build for April out yet?

User avatar
davidc
Posts: 5388
Joined: Thu Aug 18, 2011 4:56 am

Re: Properties and Methods Expansion

Post by davidc » Tue Apr 17, 2018 9:11 am

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: 5388
Joined: Thu Aug 18, 2011 4:56 am

Re: Properties and Methods Expansion

Post by davidc » Wed Apr 25, 2018 8:25 am

The build is now available.
David
SAPIEN Technologies, Inc.