我正尝试从Ruby脚本为Active Directory中的现有用户运行启用邮箱命令。我正在使用this winrm gem。到目前为止,我已经能够使用winrm和kerberos认证连接到交换服务器。我可以从powershell运行Exchange管理shell。从那里我可以执行交换命令。使用Ruby/WinRM从Linux运行Exchange Powershell命令
然而,当我尝试运行启用邮箱我得到以下错误:“操作失败的”
Active Directory operation failed on . The supplied credential for 'domain\account' is invalid.
的是逐字的。在你认为应该存在的空间中没有文字。域\帐户是我用来通过Kerberos成功连接到winrm的域。
这里是我的简单的代码:
endpoint = 'http://server:5985/wsman'
krb5_realm = 'myrealm'
winrm = WinRM::WinRMWebService.new(endpoint, :kerberos, :realm => krb5_realm)
#exch_cmd = "Get-Help Enable-Mailbox" NOTE THAT THIS COMMAND WORKS FINE
exch_cmd = "Enable-Mailbox -Identity:'user DN' -Alias:'username' -Database:'mailbox'"
command = "powershell -psconsolefile \"C:\\Program Files\\Microsoft\\Exchange Server\\V15\\bin\\exshell.psc1\" -command \". "+exch_cmd+"\""
winrm.cmd(command) do |stdout, stderr|
STDOUT.print stdout
STDERR.print stderr
end
感谢您的帮助!
我试图使用winrm python获得交换服务器。你能帮忙吗? – KMG