Powershell 异常调用";把「;加上;0“;论点:“&引用;关于Win32_TerminalServiceSetting

Powershell 异常调用";把「;加上;0“;论点:“&引用;关于Win32_TerminalServiceSetting,powershell,terminal-services,Powershell,Terminal Services,我创建了一个Powershell函数,用于在服务器上远程启用或禁用会话登录。它基本上相当于Powershell的“更改登录/启用” 它可以在大多数机器上工作,但由于某些原因我不明白,对于某些机器,它返回以下错误: Exception : System.Management.Automation.MethodInvocationException: Exception calling "Put" with "0" argument(s): "" ---> System

我创建了一个Powershell函数,用于在服务器上远程启用或禁用会话登录。它基本上相当于Powershell的“更改登录/启用”

它可以在大多数机器上工作,但由于某些原因我不明白,对于某些机器,它返回以下错误:

Exception             : System.Management.Automation.MethodInvocationException: Exception calling "Put" with "0" argument(s): "" ---> System.IO.FileNotFoundException
                           at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
                           at System.Management.ManagementObject.Put(PutOptions options)
                           at System.Management.ManagementObject.Put()
                           at Put(Object , Object[] )
                           at System.Management.Automation.MethodInformation.Invoke(Object target, Object[] arguments)
                           at System.Management.Automation.DotNetAdapter.AuxiliaryMethodInvoke(Object target, Object[] arguments, MethodInformation methodInformation, Object[] 
                        originalArguments)
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.DotNetAdapter.AuxiliaryMethodInvoke(Object target, Object[] arguments, MethodInformation methodInformation, Object[] 
                        originalArguments)
                           at System.Management.Automation.DotNetAdapter.MethodInvokeDotNet(String methodName, Object target, MethodInformation[] methodInformation, 
                        PSMethodInvocationConstraints invocationConstraints, Object[] arguments)
                           at System.Management.Automation.DotNetAdapter.MethodInvoke(PSMethod method, PSMethodInvocationConstraints invocationConstraints, Object[] arguments)
                           at System.Management.Automation.Adapter.BaseMethodInvoke(PSMethod method, PSMethodInvocationConstraints invocationConstraints, Object[] arguments)
                           at System.Management.Automation.PSMethod.Invoke(PSMethodInvocationConstraints invocationConstraints, Object[] arguments)
                           at System.Management.Automation.PSMethod.Invoke(Object[] arguments)
                           at System.Management.Automation.Language.PSInvokeMemberBinder.InvokeAdaptedMember(Object obj, String methodName, Object[] args)
                           at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
                           at System.Management.Automation.Interpreter.DynamicInstruction`2.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject          : 
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : DotNetMethodException
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

有什么想法吗?

因此,在Windows Server 2008R2上,如果未安装远程桌面会话主机角色,服务器将配置为“远程桌面管理”

如上文所述:

以下是用于管理的远程桌面的限制:

  • 默认连接(RDP Tcp)最多只允许同时进行两个远程连接

  • 无法配置授权设置

  • 无法配置RD连接代理设置

  • 无法配置用户登录模式。

  • 因此,最后我必须捕获该异常,并在该特定情况下恢复使用
    change logon/disable


    感谢@GrigorySergeev为我指明了正确的方向

    无法在多台服务器2012R2-2016主机上复制,请共享有关故障主机的更多详细信息。可能它最初没有为终端服务启用,或者服务已停止?您可能发现了@GrigorySergeev。所有服务器都运行2008R2,但我注意到它们的远程桌面会话主机配置略有不同:正常运行的服务器上有Citrix ICA 3.0,而故障服务器上只有RDP 7.1。我的测试对象中没有一个有ICA,但工作正常。Windows更新需要后续重新启动?。您是对的:出现故障的服务器没有安装RD会话主机角色,因此,配置为“远程桌面管理”。我在Technet上找到一篇文章,列出了此模式的限制:以下是远程桌面管理的限制:-默认连接(RDP Tcp)最多只允许两个同时进行的远程连接。-无法配置授权设置。-无法配置RD连接代理设置。-无法配置用户登录模式。请参阅
    $TSConnector = Get-WmiObject -Class Win32_TerminalServiceSetting -Namespace "root/cimv2/terminalservices" -Authentication PacketPrivacy
    $TSConnector.Logons = 0
    $TSConnector.Put()