Using Powershell, how are dropdown based custom webpart properties set?
<p>I have the following Powershell function:</p>

<pre><code>function Add-WebPartToPage {
[CmdletBinding()]
Param( 
   [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] 
   [System.Object]$web, 

   [Parameter(Mandatory=$true, Position=1)] 
   [string]$pageTitle,
   [Parameter(Mandatory=$true, Position=2)] 
   [Microsoft.SharePoint.SPList]$list,       

   [Parameter(Mandatory=$false, Position=3)]
   [System.Object]$webpart,

   [Parameter(Mandatory=$false, Position=4)]       
   [string]$webPartTitle,

   [Parameter(Mandatory=$false, Position=5)]       
   [string]$panelTitle,

   [Parameter(Mandatory=$false, Position=6)]       
   [int]$CSPUElevel,

   [Parameter(Mandatory=$false, Position=7)]       
   [int]$panelType 
) 
   Process 
{ 
    #if webpart specified then add it to the page
    if($webpart)
    {
        $pageName = $list.Title + "/$pageTitle.aspx"
        $pageName = $pageName -replace " ",""
        $page = $web.GetFile($pageName)
        $page.CheckOut()
        $mgr = $web.GetLimitedWebPartManager($pageName, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

        if($webPartTitle)
        {
            $webpart.Title = $webPartTitle
        }
        $webpart.ChromeType = "None"
        #++ Extended Settings
        if($webpart.GetType().Name -eq "DynamicWebPart")
        {
        # 
            $pinProperties = $webpart.GetType().GetProperties()
            foreach ($prop in $pinProperties)
            {
                if(($panelTitle) -and ($prop.Name -eq "PanelTitle"))
                {   
                    $webpart.PanelTitle = $panelTitle
                }
                if(($CSPUElevel) -and ($prop.Name -eq "CSPUElevel"))
                {
                    $webpart.CSPUElevel = $CSPUElevel
                }
                if(($panelType) -and ($prop.Name -eq "PanelType"))
                {
                    $webpart.PanelType = $panelType
                }
            }
        }
        #-- End of Extended Settings
        $mgr.AddWebPart($webpart, "FullPage", 0)
        Write-Host -f Green "Webpart $webpart.WebBrowsableObject added to the page"

        $page.CheckIn("Checked in Automatically")
        #$page.Publish("Published Automatically")
    }
 }

}   
</code></pre>

<p>Everything works fine until it gets to the extended properties of the webpart. Within that logic, the panel title will set correctly. This is a direct string assignment to the custom property. However, the CSPUElevel and PanelType are dropdowns and the assignment is never made. What is more interesting is that the CSPUElevel and PanelType don't seem to be exposed as custom properties in the same way as the Panel Title. In other words, the test for $prop.Name is never equal to "CSPUElevel" or "PanelType".</p>

<p>From the webpart (DynamicWebPart.cs):</p>

<pre><code>        protected override void CreateChildControls()
    {
        DynamicWebPartUserControl control = (DynamicWebPartUserControl)Page.LoadControl(_ascxPath);
        control.Panel = (DynamicWebPartUserControl.PanelOption)this.Panel;
        control.PanelTitle = this.PanelTitle;
        control.CSPUEBreadCrumbSelected = (DynamicWebPartUserControl.Breadcrumb)this.BreadcrumbSelected;
        Controls.Add(control);
    }
</code></pre>

<p>From the webpart (DynamicWebPartUserControl.ascx.cs):</p>

<pre><code>    public enum PanelOption
    {
        None = 0,
        AdministrativeInfo = 1,
        GeneralInfo = 2,
        Engineering = 3
    }

    public PanelOption Panel
    {
        get;
        set;
    }
</code></pre>

<p>Panel type definition:</p>

<pre><code>        private DynamicWebPartUserControl.PanelOption _Panel = 0;

    [Category("SPS - Extended Settings"),
    Personalizable(PersonalizationScope.Shared),
    WebBrowsable(true),
    WebDisplayName("Panel Type"),
    WebDescription("Please select the type of panel to display")]
    public DynamicWebPartUserControl.PanelOption Panel
    {
        get { return this._Panel; }
        set { this._Panel = value; }
    }
</code></pre>