Enable RemoteApp Full Desktop programmatically

Posted by Scott Chamberlain on Server Fault See other posts from Server Fault or by Scott Chamberlain
Published on 2012-06-21T19:25:06Z Indexed on 2012/06/21 21:17 UTC
Read the original article Hit count: 587

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?

enter image description here

I can set up all of my customizations I need by doing

#build the secrity 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)
$aceTemplet = 'O:WDG:WDD:ARP(A;CIOI;CCLCSWLORCGR;;;{0})'
$securityDescriptor = $aceTemplet -f $remoteDesktopUsersSid

#get a copy of the WMI instance
$tsRemoteDesktop = Get-WmiObject -Namespace root\CIMV2\TerminalServices -Class Win32_TSRemoteDesktop

#set settings
$tsRemoteDesktop.Name = $ServerDisplayName
$tsRemoteDesktop.SecurityDescriptor = $securityDescriptor
$tsRemoteDesktop.IconPath = $IconPath
$tsRemoteDesktop.IconIndex = $IconIndex

#push settings back to server
Set-WmiInstance -InputObject $tsRemoteDesktop -PutType UpdateOnly

however the instance of that WMI object does not exist until after you have the above box checked.

I attempted to use Set-WmiInstance to instantiate and set the settings at the same time but I keep getting errors like:

Set-WmiInstance : 
At line:53 char:16
+ Set-WmiInstance <<<<  -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

(also after running the command and getting the error it will delete the instance of Win32_TSRemoteDesktop if it already exited and un-check the box in the properties setting)

Is there any way to programmatically check that box or can anyone help with why Set-WmiInstance throws that error?

© Server Fault or respective owner

Related posts about windows-server-2008-r2

Related posts about powershell