Powershell Script to List an Account by "name description" in Windows AD

I need an example of a PowerShell script or a script that will list all accounts on a domain that begin with the letter 'b'.  If any one has an example or a script in your repository that could help me with the problem I would greatly appreciate your support. Any examples will be extremely helpful.

lipotech
lipotechSys EngAsked:
Who is Participating?
 
Will SzymkowskiSenior Solution ArchitectCommented:
import-module : The specified module 'activedirectory' was not loaded because no valid module file was found in any

You need to have Remote Server Admin Tools installed on your client machine if you are not running this on the server. If you run this directly on the Domain Controller it should work with no issues.

Once you can import the module the rest of the script will work.

Will.
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
Use the following command...
import-module activedirectory
Get-ADUser -Filter {name -like "B*"} -Properties name, samaccountname | select name, samaccountname

Open in new window


Will.
0
 
lipotechSys EngAuthor Commented:
Thank you Will.  can I execute these from the PowerShell command line?

lipotech
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Will SzymkowskiSenior Solution ArchitectCommented:
Yes you can
import-module activedirectory <press enter>
Get-ADUser -Filter {name -like "B*"} -Properties name, samaccountname | select name, samaccountname <press enter>

Will.
0
 
lipotechSys EngAuthor Commented:
Thank you.  I am testing your recommendation now.  I am new to PowerShell, but have experience with other programming languages.  I will let you know what results I experience.

Thank you tremendously for your support.

Lipotech
0
 
lipotechSys EngAuthor Commented:
Will,

How can I determine if these 'b' accounts are connect to a windows service?

Lipotech
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
Unfortunately you will not be able to verify this. The script simply retrieves all of the Accounts that have a "B" that is the first character.

Will.
0
 
lipotechSys EngAuthor Commented:
Will,

I attempted to run the command suggested.  See the following error.  How do I get around the this issue? I attempted to launch from a Window 7 client.

Lipotech



--------------------------------------------------

Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.

PS C:\Users\bobbbatt01> import-module activedirectory
import-module : The specified module 'activedirectory' was not loaded because no valid module file was found in any
module directory.
At line:1 char:1
+ import-module activedirectory
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (activedirectory:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

PS C:\Users\bobbbatt01> import-module activedirectory
import-module : The specified module 'activedirectory' was not loaded because no valid module file was found in any
module directory.
At line:1 char:1
+ import-module activedirectory
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (activedirectory:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

PS C:\Users\bobbbatt01> Get-ADUser -Filter {name -like "B*"} -Properties name, samaccountname | select name, samaccountn
ame
Get-ADUser : 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.
At line:1 char:1
+ Get-ADUser -Filter {name -like "B*"} -Properties name, samaccountname | select n ...
+ ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-ADUser:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
0
 
lipotechSys EngAuthor Commented:
Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.