Enable RemoteApp Full Desktop programmatically
- by Scott Chamberlain
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?
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?