我正在编写一个 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
会引发该错误?