Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

powershell

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 
like image 805
Sebastian Xavier Avatar asked Jul 09 '13 12:07

Sebastian Xavier


People also ask

How do I enable ADUser in PowerShell?

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.

How do I install ADUser in PowerShell?

On the Features page, expand Remote Server Administration Tools > Role Administration Tools > AD DS and AD LDS Tools, then select Active Directory module for Windows Powershell. Once selected, click Next. On the Confirmation page, click Install. Once the install completes successfully, click Close.

What module is get-ADUser in?

The Get-ADUser cmdlet is included in a special module for interacting with Active Directory – Active Directory Module for Windows PowerShell. The RSAT-AD-PowerShell module cmdlets enable you to perform various operations on AD objects.

Is not recognized as the name of a cmdlet?

If that module is missing, corrupt, or got moved, it throws up the error, “the term is not recognized as the name of a cmdlet.” You can use “get-module” in PowerShell to see if the module is present and correct. It will show you what modules are loaded, and you can add or repair them depending on your needs.


2 Answers

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

like image 199
CB. Avatar answered Sep 20 '22 21:09

CB.


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.

like image 31
Danimal111 Avatar answered Sep 20 '22 21:09

Danimal111