术语"Get-ADUser"未被识别为cmdlet的名称

Seb*_*ier 88 powershell

我已使用以下查询列出Windows 2008服务器中的用户,但失败并得到以下错误.

$server='client-pc-1';$pwd= convertto-securestring 'password$' -asplaintext -
force;$cred=new-object  -typename System.Management.Automation.PSCredential -argumentlist 'Administrator',$pwd; invoke-command -computername $server -credential 
$cred -scriptblock {Get-ADUser -Filter (enabled -ne $true)}
Run Code Online (Sandbox Code Playgroud)

例外如下:任何人都可以帮我解决这个问题吗?

The term 'Get-ADUser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct 
and try again.
    + CategoryInfo          : ObjectNotFound: (Get-ADUser:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)

CB.*_*CB. 112

如果ActiveDirectory模块存在则添加

import-module activedirectory
Run Code Online (Sandbox Code Playgroud)

在你的代码之前.

要检查是否存在,请尝试:

get-module -listavailable
Run Code Online (Sandbox Code Playgroud)

ActiveDirectory模块默认存在于Windows Server 2008 R2中,以这种方式安装:

Import-Module ServerManager
Add-WindowsFeature RSAT-AD-PowerShell
Run Code Online (Sandbox Code Playgroud)

要使其工作,您需要在域中至少有一个DC作为Windows 2008 R2并在其上安装Active Directory Web服务(ADWS).

对于Windows Server 2008,请在此处阅读如何安装它

  • 我有Windows Server 2008 R2 SP1,这里没有`activedirectory`模块. (7认同)
  • @bahrep您需要先安装它:“导入模块ServerManager”和“ Add-WindowsFeature RSAT-AD-PowerShell”。域中至少有一个DC必须是2008 R2,并装有“ Active Directory Web服务(ADWS)”。 (2认同)

Dan*_*n B 38

如果不存在,请在此处查看如何添加activedirectory模块.这可以在任何计算机上完成,然后它将允许您访问您的活动目录"域控制"服务器.

编辑

为了防止过时链接出现问题(我发现MSDN博客过去没有任何理由消失),实质上对于Windows 7,您需要下载并安装远程服务器管理工​​具(KB958830).安装后,请执行以下步骤:

  • 打开控制面板 - >程序和功能 - >打开/关闭Windows功能
  • 找到"远程服务器管理工​​具"并展开它
  • 找到"角色管理工具"并展开它
  • 找到"AD DS和AD LDS工具"并展开它
  • 选中"Windows PowerShell的Active Directory模块"旁边的框.
  • 单击"确定"并允许Windows安装该功能

Windows服务器版本应该已经确定,但如果不是,则需要下载并安装Active Directory管理网关服务.如果这些链接中的任何一个应该停止工作,您仍应该能够搜索知识库文章或下载名称并找到它们.


liv*_*ove 7

打开“打开/关闭 Windows 功能”。

确保您选择了 Active Directory 域服务。如果没有,请安装它。 在此输入图像描述


小智 6

get-windowsfeature | where name -like RSAT-AD-PowerShell | Install-WindowsFeature
Run Code Online (Sandbox Code Playgroud)

  • 盲目安装通配符搜索结果似乎是一个糟糕的主意..... (8认同)
  • “术语‘Get-WindowsFeature’不被识别为 cmdlet、函数、脚本文件或可操作程序的名称。” (8认同)

小智 5

如果没有看到Active Directory,那是因为您没有安装AD LS用户和计算机功能。转到管理-添加角色和功能。在“添加角色和功能向导”中的“功能”选项卡上,选择“远程服务器管理工​​具”,然后选择“角色管理工具”-选择“ AD DS和DF LDS工具”。

之后,您可以看到PS Active Directory程序包。


Ale*_*xei 5

对于 Windows 2018 年 10 月 10 日更新或更高版本的特殊情况,activedirectory除非RSAT: Active Directory Domain Services and Lightweight Directory Services Tools安装了可选功能(此处的说明+ 展开安装说明),否则模块不可用。

重新打开 Windows Powershell 并将import-module activedirectory按预期工作。