The PowerShell code to instantiate an object is something like this:

$rm = new-object coreservice.RenderMode

the default value of RenderMode is Publish:

PS > $rm

listing its members gives:

Name        MemberType Definition
----        ---------- ----------
CompareTo   Method     int CompareTo(System.Object target)
Equals      Method     bool Equals(System.Object obj)
GetHashCode Method     int GetHashCode()
GetType     Method     type GetType()
GetTypeCode Method     System.TypeCode GetTypeCode()
ToString    Method     string ToString(), string ToString(string format,     System.IFormatProvider provider), string To...
value__     Property   System.Int32 value__ {get;set;}

How to change its value to e.g. PreviewDynamic?

I am confused by cryptic PowerShell code like this:

$renderInstruction = new-object coreservice.RenderInstructionData -property @{RenderMode = [coreservice.RenderMode]::previewdynamic}

and the Tridion API docs saying that:

public enum RenderMode

with member PreviewDynamic

and the RenderInstructionData class with its property: RenderMode.

How to glue the .NET classes/members/properties together with a PowerShell syntax?


Your example seems to be correct (provided coreservice namespace is defined), the only problem is casing. It's [coreservice.RenderMode]::PreviewDynamic

This in Powershell:

$renderInstruction = new-object coreservice.RenderInstructionData -property @{RenderMode = [coreservice.RenderMode]::PreviewDynamic}

Is this in C#:

renderInstruction = new RenderInstructionData {RenderMode = RenderMode.PreviewDynamic}

In General, In PowerShell :: is used to access static methods and enums

| improve this answer | |
  • Right, I see the correlation now between PS and CS syntax, didn't got the :: – user348 Jun 13 '13 at 11:08

In addition to user978511's answer, I'd also like to mention that Enum values can be specified as strings.

So you could also use this format, if you prefer:

$renderInstruction.RenderMode = "PreviewDynamic"
| improve this answer | |

Thanks, didn't know that, but did discover the strings option with the FilterData, when it didn't accept a number, but it did accept a string. E.g.

$groupFilter = new-object core.OrganizationalItemItemsFilterData -property @{itemtypes = "StructureGroup"}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy