Avatar of lipotech
lipotech
Flag for United States Minor Outlying Islands asked on

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

Avatar of undefined
Last Comment
lipotech

8/22/2022 - Mon
Will Szymkowski

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

Open in new window


Will.
lipotech

ASKER
Thank you Will.  can I execute these from the PowerShell command line?

lipotech
Will Szymkowski

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

Will.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
lipotech

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

ASKER
Will,

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

Lipotech
Will Szymkowski

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
lipotech

ASKER
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
ASKER CERTIFIED SOLUTION
Will Szymkowski

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
lipotech

ASKER
Thank you.