title: Enable RemoteApp Full Desktop programmatically
body: <p>I am writing a powershell script to set up some HyperV VM's however there is one step I am having trouble automating. How do I check the box to allow Remote desktop access from the RemoteApp settings programmatically?</p>
  
  <p><img src="https://i.stack.imgur.com/lCH0T.png" alt="enter image description here"></p>
  
  <p>I can set up all of my customizations I need by doing </p>
  
  <pre><code>#build the security descriptor so the desktop only shows up for people who should be allowed to see it
  $remoteDesktopUsersSid = New-Object System.Security.Principal.SecurityIdentifier($remoteDesktopUsersGroup.objectSid[0],0)
  
  #get a copy of the WMI instance
  $tsRemoteDesktop = Get-WmiObject -Namespace root\CIMV2\TerminalServices -Class Win32_TSRemoteDesktop
  
  #set settings
  $tsRemoteDesktop.Name=$ServerDisplayName
  $tsRemoteDesktop.SecurityDescriptor= "O:WDG:WDD:ARP(A;CIOI;CCLCSWLORCGR;;;$remoteDesktopUsersSid)"
  $tsRemoteDesktop.IconPath = $IconPath
  $tsRemoteDesktop.IconIndex = $IconIndex
  
  #push settings back to server
  Set-WmiInstance -InputObject $tsRemoteDesktop -PutType UpdateOnly
  </code></pre>
  
  <p>however the instance of that WMI object does not exist until after you have the above box checked.</p>
  
  <p>I attempted to use <code>Set-WmiInstance</code> to instantiate and set the settings at the same time but I keep getting errors like:</p>
  
  <pre><code>Set-WmiInstance : 
  At line:53 char:16
  + Set-WmiInstance &lt;&lt;&lt;&lt;  -Namespace root\CIMV2\TerminalServices -Class Win32_TSRemoteDesktop -Arguments @{Alias='TSRemoteDesktop';Name=$ServerDisplayName;ShowInPortal=$true;SecurityDescriptor=$securityDescriptor}
      + CategoryInfo          : NotSpecified: (:) [Set-WmiInstance], ArgumentException
      + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.SetWmiInstance
  </code></pre>
  
  <p>(also after running the command and getting the error it will delete the instance of <code>Win32_TSRemoteDesktop</code> if it already exited and un-check the box in the properties setting)</p>
  
  <p>Is there any way to programmatically check that box or can anyone help with why <code>Set-WmiInstance</code> throws that error?</p>