Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to activate a feature with custom properties. It is easy to do in onet.xml by providing Properties:

<Feature ID=“78277796-98D9-4276-B7D2-E3374AAC43D8“>
      <Properties>
            <Property Key=“MyProperty1“ Value=“FALSE“ />
            <Property Key=“MyProperty2“ Value=“6ECFC841-7FFF-4E06-9D50-0678CC43696D“ />
            <Property Key=“MyProperty3“ Value=“TRUE“ />
            <Property Key=“MyProperty4“ Value=“Custom Data“/>
      </Properties>
</Feature>

In Code I have seen, we can use Reflection to specify custom properties and Yaroslavs remake. How could one specify custom properties when activating feature in powershell:

Enable-SPFeature ...
share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

It's not possible throught Enable-SPFeature if you need it you'll have to write your own cmdlet, there a guide for doing that here

In that cmdlet, you can use the reflection hack you linked to, but note that when you're using reflection to find non-public methods you run the risk of any update/hotfix/SP breaking your code.

share|improve this answer
    
Thank you for your answer. I agree with you. It isn't reliable to use reflection because a new patch can change internal methods. But I was curious about creating cmdlets, so I created this one: sp-lend-id.taprat The description is on my blog –  Anatoly Mironov Apr 10 '12 at 20:15
add comment

It sounds like what you have is a configurable component. If that is the case, you should implement configuration properly instead of hacking/reflecting an object to make is suit your purpose.

The patterns & practices group discusses configuration in "The Application Setting Manager" section of their guidance. The guidance also includes sample code for a List-backed configuration store.

share|improve this answer
    
Thank you for your answer! Could you provide an example how to implement the configuration "properly"? –  Anatoly Mironov Apr 5 '12 at 13:40
    
Read content at the provided link. –  Paul Schaeflein Apr 5 '12 at 13:41
1  
Allright, one can do much with Application Settings Manager like creating new configurations when activating feature But how can we put properties into the feature when we enable it? –  Anatoly Mironov Apr 5 '12 at 13:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.