【问题标题】:Try to import module ActiveDirectory on a linux powershell尝试在 linux powershell 上导入模块 ActiveDirectory
【发布时间】:2021-04-21 14:03:31
【问题描述】:

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

【问题讨论】:

  • ActiveDirectory 模块带有用于 Windows 的 RSAT - 它不适用于 CentOS
  • 好的,谢谢老兄!

标签: php powershell


【解决方案1】:

简短的回答是……你不能。 .net 的centos 平台版本还不支持[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 模块。我不太熟悉它,所以我只是从一个类似的问题链接工作示例代码:Modifying Active Directory Passwords via ldapmodify

【讨论】:

    【解决方案2】:

    我知道线程很旧,但另一种方法是将调用请求发送到您的域控制器/其他 Windows 服务器。

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

    【讨论】:

      猜你喜欢
      • 2021-08-17
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多