The term 'Get-ADUser' is not recognized as the name of a cmdlet

Powershell

Powershell Problem Overview


I have used the following query to list the users in a windows 2008 server, but failed and got the below error.

$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)}

The exception is given below...Can anyone help me to solve this?

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

Powershell Solutions


Solution 1 - Powershell

If the ActiveDirectory module is present add

import-module activedirectory

before your code.

To check if exist try:

get-module -listavailable

ActiveDirectory module is default present in windows server 2008 R2, install it in this way:

Import-Module ServerManager
Add-WindowsFeature RSAT-AD-PowerShell

For have it to work you need at least one DC in the domain as windows 2008 R2 and have Active Directory Web Services (ADWS) installed on it.

For Windows Server 2008 read here how to install it

Solution 2 - Powershell

Check [here] for how to add the activedirectory module if not there by default. This can be done on any machine and then it will allow you to access your active directory "domain control" server.

EDIT

To prevent problems with stale links (I have found MSDN blogs to disappear for no reason in the past), in essence for Windows 7 you need to download and install Remote Server Administration Tools (KB958830). After installing do the following steps:

  • Open Control Panel -> Programs and Features -> Turn On/Off Windows Features
  • Find "Remote Server Administration Tools" and expand it
  • Find "Role Administration Tools" and expand it
  • Find "AD DS And AD LDS Tools" and expand it
  • Check the box next to "Active Directory Module For Windows PowerShell".
  • Click OK and allow Windows to install the feature

Windows server editions should already be OK but if not you need to download and install the Active Directory Management Gateway Service. If any of these links should stop working, you should still be able search for the KB article or download names and find them.

Solution 3 - Powershell

get-windowsfeature | where name -like RSAT-AD-PowerShell | Install-WindowsFeature

Solution 4 - Powershell

For the particular case of Windows 10 October 2018 Update or later activedirectory module is not available unless the optional feature RSAT: Active Directory Domain Services and Lightweight Directory Services Tools is installed (instructions here + uncollapse install instructions).

Reopen Windows Powershell and import-module activedirectory will work as expected.

Solution 5 - Powershell

If you don't see the Active Directory, it's because you did not install AD LS Users and Computer Feature. Go to Manage - Add Roles & Features. Within Add Roles and Features Wizard, on Features tab, select Remote Server Administration Tools, select - Role Admininistration Tools - Select AD DS and DF LDS Tools.

After that, you can see the PS Active Directory package.

Solution 6 - Powershell

Open Turn On/Off Windows Features.

Make sure you have Active Directory Domain Services selected. If not, install it. enter image description here

Solution 7 - Powershell

For Windows 11 (and maybe Windows 10), you can execute the below command in powershell

Get-WindowsCapability -Online | Where-Object {$_.Name -like "*ActiveDirectory.DS-LDS*"} | Add-WindowsCapability -Online

Solution 8 - Powershell

If you are using windows 10 and encounter this error, you can solve this error message by installing RSAT (Remote Server Administration Tools).

https://www.microsoft.com/en-us/download/details.aspx?id=45520

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSebastian XavierView Question on Stackoverflow
Solution 1 - PowershellCB.View Answer on Stackoverflow
Solution 2 - PowershellDanimal111View Answer on Stackoverflow
Solution 3 - PowershellmzperxView Answer on Stackoverflow
Solution 4 - PowershellAlexei - check CodidactView Answer on Stackoverflow
Solution 5 - PowershellMr. Johnathan NguyenView Answer on Stackoverflow
Solution 6 - Powershelllive-loveView Answer on Stackoverflow
Solution 7 - PowershellLeon TaysonView Answer on Stackoverflow
Solution 8 - PowershellHO LI PinView Answer on Stackoverflow