Link to home
Create AccountLog in
Avatar of Bobby Batts
Bobby BattsFlag for United States of America

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
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

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

Open in new window


Will.
Avatar of Bobby Batts

ASKER

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

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

Will.
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
Will,

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

Lipotech
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.
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
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thank you.