尝试在Linux Powershell上导入ActiveDirectory模块

4

在我的网页中,我想更改一些帐户的密码。因此,我得到了一个 PowerShell 脚本。在这个脚本中,我需要导入 Active-Directory 模块来更改帐户密码。我的服务器运行在 CentOS 上,所以我在它上面安装了 PowerShell。但是当我执行:Import-Module ActiveDirectory 时,控制台返回“Import-Module: 由于在任何模块目录中都没有找到有效的模块文件,因此未加载指定的模块 'ActiveDirectory'。”


5
“ActiveDirectory”模块是随着Windows RSAT一起提供的,它无法在CentOS上工作。” - Mathias R. Jessen
2个回答

4
简短的回答是...你不能。CentOS平台版本的.NET不支持[System.DirectoryServices]类型/类,我怀疑它们不会很快迁移过来。Powershell的ActiveDirectory模块需要这些才能运行,因此目前无法在Powershell中完成此操作:
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
MethodInvocationException: Exception calling "GetCurrentDomain" with "0" argument(s): "System.DirectoryServices is not supported on this platform."

另一种选择是使用来自CentOS软件包的LDAP命令。以下是一些示例:

# Change a password that you already know - works with almost any configuration
# You can provide the password from a file or as a parameter. By default it will prompt.
# part of package samba-common-tools

smbpasswd -U MyUsername -r ad.domain.tld
  Old SMB password:
  New SMB password:
  Retype new SMB password:

当你不知道当前密码时,为AD用户更改密码会更加复杂,并需要在您的计算机上进行更具体的配置,但只需使用passwd即可完成以下操作:

  • 您的CentOS计算机已正确加入域
  • 您正在使用具有对AD写权限的管理员帐户
  • 您已在\etc\sssd\sssd.conf中使用chpass_provider=ad配置了sssd
passwd DOMAIN\\SomeUsername

否则,在Linux上最好的选项是通过Python的ldap模块。我不太熟悉它,因此我只链接了一个类似问题的工作示例代码:通过ldapmodify修改Active Directory密码


1

我知道这个帖子很老了,但另一种选择是向您的域控制器/其他Windows服务器发送调用请求。

Invoke-Command -ComputerName Server01 -Credential Domain01\User01 -ScriptBlock { Get-Culture }


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接