Trying to understand how to access Properties

Jun 25, 2014 at 12:27 PM
When I use
get-item dte:\Solution\Projects\Project1 | select Properties
I get something that looks reasonable:
{ExtenderCATID, Extender, ExtenderNames, Name}                                                                                                                                                                                                                                  
But I can't figure out how to access the values of the properties. How is this done?

Jun 25, 2014 at 1:09 PM
Edited Jun 25, 2014 at 1:10 PM
I found this ( (Accessing UIHierarchy to configure a file's build action )) which suggested that the right method is to do this:
$project1 = get-item dte:\Solution\Projects\Project1
$project1.Properties | foreach { echo $_.Name $_.Value }
Is there another way to access these in a pipeline?

Jun 26, 2014 at 12:15 PM
I think what you're looking for is here:
dir dte:\solution\projects\projecct1\properties\itemproperties
Each property node under itemproperties support get- and set-item; in addition, every node in the /solution/projects hive supports an itemproperties folder, so you'll find one for each individual file and folder in the solution.
Jun 26, 2014 at 1:24 PM
Edited Jun 26, 2014 at 1:25 PM
As it turns out I was confused about what I was doing, but in an interesting way. I changed the actual name of the item I was working with to "Project1". I had assumed the item I chose was a project, but it really was a folder. The solution you give doesn't work on folders. It works just fine on projects, however.

As best I can tell, for folders the path for properties on a folder is "ProjectProperties", i.e. the following works on folders:
dir dte:\solution\projects\StudioShellTestFolder\ProjectProperties
As aid to others trying to discover functionality, I would have never guessed the answer (i.e. using "itemproperties"). Having seen it, I was able to see how to arrive at the answer for folders. When I ran
dir dte:\solution\projects\StudioShellTestClassLibrary\properties | get-member
I saw
   TypeName: CodeOwls.StudioShell.Paths.Items.ShellContainer
PSChildName   NoteProperty System.String PSChildName=ItemProperties
When I ran
dir dte:\solution\projects\StudioShellTestFolder | get-member
I saw
   TypeName: CodeOwls.StudioShell.Paths.Items.ShellContainer
PSChildName   NoteProperty System.String PSChildName=ProjectProperties
I believe the "PSChildName" gives the name of the path to children on the object.

BTW, great talk at the PillyDotNet Code Camp. Thanks Jim.
Jul 1, 2014 at 11:29 AM
I have discovered that my lack of understanding of powershell led me to a great deal of confusion here. In particular, the "Select-Object" cmdlet does not do what I supposed it did. I assumed it behaved like "select" in LINQ. It sort of does, but instead of returning the underlying item, it creates a new temporary object to which it attaches the value. For instance, if you have a project called StudioShellTestClassLibrary, the following command seems to return a boolean:
get-item dte:\solution\Projects\StudioShellTestClassLibrary | Select IsDirty
That's an illusion. It actually creates a new temporary type to which it attaches a property "IsDirty". You can see this by running:
get-item dte:\solution\Projects\StudioShellTestClassLibrary | Select IsDirty | get-member
   TypeName: Selected.CodeOwls.StudioShell.Paths.Items.ProjectModel.ShellVSProject2

Name        MemberType   Definition                    
----        ----------   ----------                    
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()             
GetType     Method       type GetType()                
ToString    Method       string ToString()             
IsDirty     NoteProperty System.Boolean IsDirty=False  
This is equivalent to something like the following LINQ command:
select new { IsDirty = item.IsDirty }
To get the underlying boolean, you have to use the "-expand" flag on "Select"
get-item dte:\solution\Projects\StudioShellTestClassLibrary | Select -expand IsDirty | get-member
   TypeName: System.Boolean
Name        MemberType Definition                                                                                                                                            
----        ---------- ----------                                                                                                                                            
CompareTo   Method     int CompareTo(System.Object obj), int CompareTo(bool value), int IComparable.CompareTo(System.Object obj), int 
My original command should have used:
get-item dte:\Solution\Projects\Project1 | select -expand Properties
This is probably old hat to powershell power users, but was a surprise to me.

Jul 2, 2014 at 3:46 PM
Ah, yes. You have achieved a new level of harmony with the PowerShell, grasshopper.

Honestly this little bit annoys the hell out of me. I almost NEVER want what select-object does without the -expand parameter. So have a function in my profile:
function select-expandedProperty( $property) { $input | select-object -expand $property }
and an alias:
new-alias -name isolate -value 'select-expandedProperty'
so I can do things like this:
get-item dte:/solution/projects/project1 | isolate properties