以编程方式启用RemoteApp Full Desktop

时间:2012-06-21 19:25:07

标签: windows-server-2008-r2 powershell wmi

我正在编写一个PowerShell脚本来设置一些HyperV VM但是有一步我无法自动化。如何选中此框以允许以编程方式从RemoteApp设置进行远程桌面访问?

enter image description here

我可以通过

设置我需要的所有自定义设置
#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

但是,在检查上面的框之后,该WMI对象的实例才会存在。

我尝试使用Set-WmiInstance同时实例化和设置设置,但我不断收到如下错误:

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

(同样在运行命令并收到错误后,如果已经退出,它将删除Win32_TSRemoteDesktop的实例,并取消选中属性设置中的框)

有没有办法以编程方式检查该框,或者任何人都可以帮助解决为什么Set-WmiInstance会抛出该错误?

1 个答案:

答案 0 :(得分:1)

如果您运行的是Windows Server 2008 R2,则可以使用Windows PowerShell模块的远程桌面服务提供程序。

您可以在technet上阅读有关它的信息link

我使用此guide来满足我的所有需求。