我正在编写一个PowerShell脚本来设置一些HyperV VM但是有一步我无法自动化。如何选中此框以允许以编程方式从RemoteApp设置进行远程桌面访问?
我可以通过
设置我需要的所有自定义设置#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
会抛出该错误?