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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Defend Against the Q2 Top Security Threats

Were you aware that overall malware worldwide was down a surprising 42% from Q1'18? Every quarter, the WatchGuard Threat Lab releases an Internet Security Report that analyzes the top threat trends impacting companies worldwide. Learn more by viewing our on-demand webinar today!

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lipotechSys EngAuthor Commented:
Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.