Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

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

XML
$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...

XML
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


Can anyone help me to solve this?

Thanks & Regards
Sebastian
Posted

1 solution

Maybe something like this within your invoke

-scriptblock { Import-Module ActiveDirectory; Get-ADUser -Filter 'enabled -ne "true"' }


Alternatively just install RSAT (with the AD PS-module) on the computer where you intend to run the script and no invoke would be needed.
 
Share this answer
 
v3
Comments
Sebastian T Xavier 11-Jul-13 6:55am    
Thanks for your help, But unfortunately I am ended up in another error...
The term 'enabled' 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: (enabled:String) [],
CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
notjustme 11-Jul-13 12:09pm    
Try it like this;

Get-ADUser -Filter 'Enabled -ne "true"'
Sebastian T Xavier 15-Jul-13 2:03am    
Its working now... Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900