2017-07-24 35 views
2

我创建了Powershell函数来在服务器上远程启用或禁用会话登录。它基本上是“更改登录/启用”的Powershell等价物。在Win32_TerminalServiceSetting上调用“Put”和“0”参数:“”的异常

它适用于大多数机器,但由于某些原因,我不明白,对一些人来说返回以下错误:

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 : {} 

错误堆栈跟踪并不能帮助我。

我在所有机器上都使用相同的本地管理员用户运行相同的代码。

下面是实际的代码片段:

$TSConnector = Get-WmiObject -Class Win32_TerminalServiceSetting -Namespace "root/cimv2/terminalservices" -Authentication PacketPrivacy 
$TSConnector.Logons = 0 
$TSConnector.Put() 

任何想法?

+0

无法在多台服务器2012R2-2016主机上重现,请分享有关故障主机的更多细节。也许它首先没有启用终端服务或服务停止? –

+0

你可能会在@GrigorySergeev上。所有服务器都在运行2008R2,但我注意到他们的远程桌面会话主机配置略有不同:那些工作正常的服务器上有Citrix ICA 3.0,而失败的服务器只有RDP 7.1。 – geoced

+0

以及我的测试对象都没有ICA,但工作正常。 Windows更新需要后续重启? –

回答

1

事实证明,在Windows Server 2008 R2上,如果未安装远程桌面会话主机角色,则服务器配置为“用于管理的远程桌面”。

this technet article解释说:

以下是远程桌面的局限性管理:

  1. 默认的连接(RDP-TCP)只允许最多两个同时远程连接。

  2. 无法配置授权设置。

  3. RD连接代理设置无法配置。

  4. 无法配置用户登录模式。

所以在最后我不得不捕获了异常,并恢复到在特定情况下使用change logon /disable

对@GrigorySergeev的荣誉指向我在正确的方向!

相关问题