Page 1 of 2

Properties and Methods Expansion

Posted: Tue Mar 20, 2018 2:01 am
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.

Re: Properties and Methods Expansion

Posted: Tue Mar 20, 2018 9:51 am
by davidc
Yes, PowerShell Studio provides PrimalSense information for Cmdlets.
Cmdlet PrimalSense.png
Cmdlet PrimalSense.png (23.15 KiB) Viewed 33074 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.

Re: Properties and Methods Expansion

Posted: Tue Mar 20, 2018 9:16 pm
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

Re: Properties and Methods Expansion

Posted: Wed Mar 21, 2018 11:16 am
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 32938 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).

Re: Properties and Methods Expansion

Posted: Wed Mar 21, 2018 11:20 am
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.

Re: Properties and Methods Expansion

Posted: Wed Mar 21, 2018 10:43 pm
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 32856 times
Thanks. Do you have a timeline on when the new build is coming out?

Regards,
Larry

Re: Properties and Methods Expansion

Posted: Thu Mar 22, 2018 8:16 am
by davidc
I can't provide a exact timeline, but we usually release a new build for PowerShell Studio every month.

Re: Properties and Methods Expansion

Posted: Mon Apr 16, 2018 7:00 pm
by larrybtagao
Hi David - Was just wondering, is the build for April out yet?

Re: Properties and Methods Expansion

Posted: Tue Apr 17, 2018 9:11 am
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.

Re: Properties and Methods Expansion

Posted: Wed Apr 25, 2018 8:25 am
by davidc
The build is now available.