Are there publics Enums for ExtendedPropertyDefinition IDs? - powershell

Much like in the example from this question I see many code snippets on the web using magic numbers when making ExtendedPropertyDefinition. Example:
Dim PR_DELETED_ON As New ExtendedPropertyDefinition(26255, MapiPropertyType.SystemTime)
Dim PR_SEARCH_KEY As New ExtendedPropertyDefinition(12299, MapiPropertyType.Binary)
I have sort of found a reference location for these on MSDN. I can look them up individually as supposed to one large table. Here is the one for PR_DELETED_ON like in the above example
+------------------------+---------------+
| Associated properties: | PR_SEARCH_KEY |
+------------------------+---------------+
| Identifier: | 0x300B |
+------------------------+---------------+
| Data type: | PT_BINARY |
+------------------------+---------------+
| Area: | ID properties |
+------------------------+---------------+
0x300b being 12299 in decimal
I hate magic numbers so I was looking for an enum for this in the EWS API. I wrote this snippet to (hopefully) show me all the enums exposed.
$obj = [Reflection.Assembly]::LoadFile("C:\Program Files (x86)\EWSManagedAPI\Microsoft.Exchange.WebServices.dll")
$obj.GetTypes() | Where-object{$_.isenum -and ($_.ispublic -or $_.isnestedpublic)} | ForEach-Object{
$props = #{Name = $_.FullName}
[enum]::GetValues($_) | ForEach-Object{
$props.Integer = [int64]$_
$props.Text = $_
[pscustomobject]$props
}
}
I didn't see anything in the output that matched what I was looking at above. Does anyone know if there is a preexisting enum for these properties? If not that is fine. I just assumed there would be something out there.
Not the end of the world but I couldn't find them myself. Might explain why code snippets keep referencing to them.

No there is nothing in the EWS Managed API for this and AFAIK there is no master list maintained by Microsoft. There are also different types of Properties eg Tagged and Named properties and to use an Extended property in EWS you need to first define and tell Exchange to either return or set that property so EWS doesn't allow you to enumerate all the Extended properties on a Item like MAPI. The closest list that I know of is the one from the EWSEditor which is pretty comprehensive https://ewseditor.codeplex.com/SourceControl/latest#EWSEditor/PropertyInformation/KnownExtendedPropertiesData.cs . The Mapi include files also have a good list eg https://github.com/openchange/openchange/blob/master/properties_enum.h (but these are only tagged properties).

Related

Use powershell to get instance description and tags

Is there a way of getting instance's description (eg, instance ID, AMI ID, VPC ID....etc) and tags using Powershell?
I tried Get-EC2Instance | select * but it doesn't give all the information I need.
Good starting point would be to store your instances in a variable.
$ec2 = Get-EC2Instance
$ec2.instances
will display all the info you can get.
Same can be done like this
(Get-EC2Instance).Instances
or filter only what you need.
(Get-EC2Instance).Instances | select-object ImageId,InstanceId,VpcId

Filtering in Powershell

I have an array of objects called $listy.
I am looking for object for which property $_.WorkflowAssociations.Count is greater than 0.
When I select that property I can see that several objects fulfill my criteria:
$listy | select title, workflowassociations.count
However when I use where: $listy | where {$_.WorkflowAssociations.Count -gt 0} none of the objects are listed:
I have the same issue with $_.Views.Count property. Other numeric properties seem to filter without issues. Is it because of the point (.)? Why? The property is called exactly Views.Count:
As #EtanReisner already pointed out in the comments to your question: if you have a property name containing a dot (like WorkflowAssociations.Count) you must put the name in quotes when trying to access it via dot notation:
$listy | Where-Object { $_.'WorkflowAssociations.Count' -gt 0 }
If you don't, the term $_.WorkflowAssociations.Count will be interpreted as the property Count of a property WorkflowAssociation of the current object ($_). Which, of course, doesn't exist.

Powershell UIAutomation - how to identify methods supported by an object?

I'm just learning a bit of UIA with PoSH. So far so good, albeit somewhat basic.... I have worked out the following:
$np = get-uiawindow -class 'notepad' -name '*'
$npedit = $np | Get-UiaDocument
# $npedit | send-keys "abc"
$npedit | Set-UiaControlText "def"
$currtext = $npedit | Get-UiaDocumentRangeText
So then the next obvious stage was to automate driving ie, or chrome...
$ie = Get-UiaWindow -class 'ieframe' -name 'environment agenc*'
$addbar = $ie | Get-UiaPane -automationid '40966' -class "rebarwindow32"
$addbar | Set-UiaControlText "news.bbc.co.uk"
But it seems objects of class rebarwindow32 do not support "Set-UiaControlText".
Similarly, in my earlier experimenting, I also tried automating the windows calculator. Clicking buttons etc is easy enough, but trying to read the results of any calculation proved more challenging - the UIAutomationSpy showed it as a UiaText object of class "Static".
So all this is aimed at asking a fairly simple question - how can I identify what methods are supported by any one object - I'm not asking just HOW to get the current value in the calculator results, or HOW to set the IE browser address bar... but HOW to FIND OUT for myself, what methods any one object I have identified supports.
Everything I've googled so far has shown specific examples of "How to do this or that" (eg select a menu, set some text) - but all very specific.
Based on comments from mike z below, I've now tried GetSupportedPatterns, which (based on a bit of googling on GetSupportedPatterns, is exactly what I need!).
However, if (based on my sample code above) I do $np.GetSupportedPatterns() I get:
Cached Current
------ -------
UIAutomation.UiaWindowPattern+Window... UIAutomation.UiaWindowPattern+Window...
UIAutomation.UiaTransformPattern+Tra... UIAutomation.UiaTransformPattern+Tra...
Which doesn't seem to tell me very much - and I cannot widen my window? Also, why only the cached operations, rather than the full list?
Thanks
Steve

Using DBFit variables for other Fixtures

Is it possible to use a DbFit variable in another fixture? For example, if I create a query in dbfit with a variable <<firstname as follows:
SELECT * FROM System.Columns Where ColumnName= 'FirstName' | <<firstname |
Is it possible to include a reference to that page in another suite of tests that use a column fixture or RestFixture and call the variable name to check against the database?
In the RestFixture, I'm checking a database column name against a node so can I do something like:
| GET | /resources/6 | | //${firstname} |
Where I'm checking if an xml node named FirstName exists in the database.
With fitSharp (.NET), it is. With Java, I'm not sure.
I was struggling with the same issue, imo it's hard to find any good documentation. I stumbled upon the answer skimming some arbitrary tests somewhere.
You can access the symbol in RESTFixture using %variablename%.
RestFixture
| GET | /resources/6 | | //%firstname% |

How can I summarize an object the same way Format-List does?

For example, looking at a processes threads shows something like this:
PS C:\> (Get-Process)[0] | Format-List -Property Threads
Threads : {1548, 1600, 15940, 13996}
But if you actually grab that property directly, it looks like this:
PS C:\> (Get-Process)[0].Threads
BasePriority : 8
CurrentPriority : 9
Id : 1548
IdealProcessor :
PriorityBoostEnabled :
PriorityLevel :
PrivilegedProcessorTime :
StartAddress : 8790537024736
StartTime :
ThreadState : Wait
TotalProcessorTime :
UserProcessorTime :
WaitReason : UserRequest
ProcessorAffinity :
Site :
Container :
BasePriority : 8
... etc
Format list obviously has a method to summarize objects intelligently. It took a list of objects, pulled out a representative property from each one, and displayed it as a short array. I cannot find a method or cmdlet that allows me to summarize an collection of objects in the same manner.
I want to be able to pass an arbitrary collection of objects to a method and have it summarize. This is used when listing email addresses in Exchange objects, listing groups in AD objects, and many other places... I doubt these are all special cases.
To expand (after learning more from #JoelSmith's comments):
.NET Objects have formatting definitions that are used by Powershell when formatting output. Additional details are available using help about_Format.ps1xml[1]. These definitions are generic and can be accessed by any command, but by default there are no functions in Powershell to directly retrieve the output of an object property directly as it would be displayed in Format-List.
One hackish workaround is to split and strip the output like so:
(Get-Mailbox user | Format-List -Property Languages | Out-String).Split(':')[1].Trim()
# => {en-US,fr-CA}
However this method is extremely fragile, and will fail when the output spans multiple lines or contains a colon in the output:
(Get-Mailbox user | Format-List -Property EmailAddresses | Out-String).Split(':')[1].Trim()
# => {smtp
What is needed is a method that reads the formatting definition defined for the object and retrieves it directly, then use it to output the desired string. I have failed to find any example online.
You can use the
PSStandardMembers.DefaultDisplayProperty
and
PSStandardMembers.DefaultDisplayPropertySet
properties of your objects to determine the default properties that should be displayed for each type. You can read more about it here. We've run into a similar problem recently in our like PowerShell project. You can find this discussion we've had helpful. There are some subtle differences between PS v2 and v3 which we debate on that thread.
Usually .ToString() works but sometimes they forget to implement that method.
(Get-Process)[0] | %{$_.Threads.Id}
EDIT: to answer your comment below
(Get-Process)[0] | Format-List -Property Threads | Out-String
Unfortunately not all cmdlets are the same.
Are you looking for something like this?
(Get-Process)[0].Threads | Format-Table -Property ID -AutoSize
Id
--
13060
13064
13068
13072
13076
13080
13084
This needs to be customized for each cmdlet depending on what the output is and what fields you need. The reason it doesn't work with just (Get-Process)[0] | Format-Table -Property Threads -AutoSize is because Threads returns thread-objects, and an array of objects are displayed like your first sample (string-presentation of your objects in a collection { .. }) .
Here's what I can tell so far:
The Id property is the default display property for a thread object (System.Diagnostics.ProcessThread).
I couldn't find any tracks of this in any of PowerShell's type files but I can change the way Format-* display threads (requires PowerShell 3.0).
By default the format cmdlets prints the Id value of each thread object:
Threads : {1548, 1600, 15940, 13996}
Formatting cmdlets checks the value of the $FormatEnumerationLimit variable (default is 4) to decide how to format the object.
If the result is one object (scalar) only it will print as:
Threads : 1548
If it's a collection of items and the collection count is up to the value of $FormatEnumerationLimit (4) it will display as:
Threads : {1548, 1600, 15940, 13996}
A count greater than $FormatEnumerationLimit will look like (... indicates that there are more objects):
Threads : {1548, 1600, 15940, 13996...}
I can tell Id is the default property in use because I can change it to another property and see its value reflecting in the output.
For example, Here I'm setting the ThreadState as the default display property:
PS> Update-TypeData -TypeName System.Diagnostics.ProcessThread -DefaultDisplayProperty ThreadState -Force
PS> (Get-Process)[0] | Format-List -Property Threads
Threads : {Wait, Wait, Wait, Wait...}
# revert back
PS> Update-TypeData -TypeName System.Diagnostics.ProcessThread -DefaultDisplayProperty Id -Force
Hope that helps