title: Load WinForm Object from CliXml PS
body: <p>How can one save and load the properties of GUI objects from a CliXml file?   Saving mwe is below, with failed attempt to load commented out. directly importing changes object type from <code>System.Windows.Forms.Button</code> to <code>System.Management.Automation.PSObject</code>. Attempts to loop over the saved properties failed.</p>
  <pre><code>Add-Type -AssemblyName System.Windows.Forms
  [System.Windows.Forms.Application]::EnableVisualStyles()
  Remove-Variable * -ErrorAction SilentlyContinue
  
  $form = New-Object system.Windows.Forms.Form
  $form.ClientSize = New-Object System.Drawing.Point(100,100)
  $form.text = &quot;Form&quot;
  $form.TopMost = $false
  $form.FormBorderStyle = &quot;FixedSingle&quot;
  $form.MaximizeBox = $false
  
  $TestButton = New-Object system.Windows.Forms.Button
  $TestButton.text = &quot;Test&quot;
  $TestButton.width = 85
  $TestButton.height = 30
  $TestButton.location = New-Object System.Drawing.Point(0,0)
  $TestButton.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12)
  $TestButton.Enabled = $true
  
  $path = &quot;./vars/test.xml&quot;
  $TestButton | Export-CliXml $path
  
  $TestButton.Enabled = $false
  
  #$TestButton.GetType().FullName #For comp below
  #$TestButton = Import-CliXml $path #Import the saved properties - intention is that this enables button again
  #$TestButton.GetType() #The import changes the type. How to load saved properties and avoid this? 
  
  $form.Controls.Add($TestButton)
  [void]$form.ShowDialog()
  </code></pre>