远程执行脚本时,ADWS未运行

时间:2019-12-12 08:41:31

标签: powershell web-services active-directory powershell-remoting

我有一个脚本,可以返回某个用户的所有组。它通过使用Active Directory模块和一些Get-ADGroup,Get-ADUser命令来实现。如果仅运行脚本,它就可以正常工作,但是我需要以其他用户身份执行它。我通过创建第二个脚本来执行此操作,该脚本调用了第一个脚本。到目前为止,一切都很好。但是,从另一个脚本调用第一个脚本时,出现错误消息:

  

无法联系服务器。这可能是因为该服务器没有   存在,当前已关闭或没有Active Directory   Web服务正在运行。

这禁止我获得用户的必要组,而我只能从我域中的DC获得。 ADWS在我的DC上运行,并且在使用Get-ADGroup / Get-ADUser命令时指定了DC。当我与其他用户从另一个脚本调用它时,它只是不起作用。

请参见下面的代码:

        Set-Executionpolicy -Scope CurrentUser unrestricted
        Enable-PSRemoting -Force

        $creds = Get-Credential -credential $Username
        Invoke-Command -FilePath $Path -ComputerName $Client -Credential $creds
        $DC = 'ESX-DC'
        $ADGroup = Get-ADGroup -Server $DC -Identity $Identity -Properties MemberOf, Description

感谢您的帮助。如果您需要有关我的代码的更多信息,请告诉我。

编辑:

如果有帮助,请参阅完整的错误消息:

Exception             : Microsoft.ActiveDirectory.Management.ADServerDownException: Unable to contact the server. This may be because this server does not exist, it is currently down, or it 
                        does not have the Active Directory Web Services running. ---> System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by 
                        an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was 
                        '00:01:59.9910000'. ---> System.IO.IOException: The read operation failed, see inner exception. ---> System.ServiceModel.CommunicationException: The socket 
                        connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network 
                        resource issue. Local socket timeout was '00:01:59.9910000'. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
                           at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
                           --- End of inner exception stack trace ---
                           at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
                           at System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
                           at System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
                           at System.ServiceModel.Channels.ConnectionStream.Read(Byte[] buffer, Int32 offset, Int32 count)
                           at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
                           at System.Net.Security.NegotiateStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
                           at System.Net.Security.NegotiateStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
                           --- End of inner exception stack trace ---
                           at System.Net.Security.NegotiateStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
                           at System.Net.Security.NegotiateStream.Read(Byte[] buffer, Int32 offset, Int32 count)
                           at System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
                           --- End of inner exception stack trace ---

                        Server stack trace: 
                           at System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
                           at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)
                           at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& 
                        timeoutHelper)
                           at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
                           at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
                           at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
                           at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
                           at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
                           at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
                           at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
                           at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
                           at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
                           at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
                           at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

                        Exception rethrown at [0]: 
                           at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
                           at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
                           at Microsoft.ActiveDirectory.WebServices.Proxy.Resource.Get(Message request)
                           at Microsoft.ActiveDirectory.Management.AdwsConnection.SearchAnObject(ADSearchRequest request)
                           --- End of inner exception stack trace ---
                           at Microsoft.ActiveDirectory.Management.AdwsConnection.InitializeForAutoReconnect[TChannel](Boolean& isAutoReconnecting, TChannel& channel, ChannelFactory`1& 
                        chFactory, String endpointName, CommunicationException& commException)
                           at Microsoft.ActiveDirectory.Management.AdwsConnection.SearchAnObject(ADSearchRequest request)
                           at Microsoft.ActiveDirectory.Management.AdwsConnection.Search(ADSearchRequest request)
                           at Microsoft.ActiveDirectory.Management.ADWebServiceStoreAccess.Microsoft.ActiveDirectory.Management.IADSyncOperations.Search(ADSessionHandle handle, 
                        ADSearchRequest request)
                           at Microsoft.ActiveDirectory.Management.ADObjectSearcher.GetRootDSE()
                           at Microsoft.ActiveDirectory.Management.Commands.ADCmdletBase.GetRootDSE()
                           at Microsoft.ActiveDirectory.Management.Commands.ADCmdletBase.GetConnectedStore()
                           at Microsoft.ActiveDirectory.Management.Commands.ADCmdletBase.GetCmdletSessionInfo()
                           at Microsoft.ActiveDirectory.Management.Commands.ADGetCmdletBase`3.ProcessRecordOverride()
                           at Microsoft.ActiveDirectory.Management.Commands.ADCmdletBase.ProcessRecord()

0 个答案:

没有答案