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
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.
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.
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.
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.
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
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With