PS C:\> 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:14
+ Import-Module <<<< Activedirectory
+ CategoryInfo : ResourceUnavailable: (Activedirectory:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
To ensure that you have the Active Directory module available for import, you can run the Get-Module –ListAvailable command in Windows PowerShell console.
Get-ADuser -Filter * -Properties Manager,DisplayName,Company
To return the objects with all properties:
Get-ADuser -Filter * -Properties *
To return all users from a specific Organizational Unit (OU):
Get-ADuser -Filter * -SearchBase "OU=Users,OU=HQ,DC=Max,DC=com"
To save the result to a csv file, you can use the Export-Csv command.
Get-ADuser -Filter * -Properties Manager,DisplayName,Company -SearchBase "OU=Users,OU=HQ,DC=Max,DC=com" | Export-csv C:\report.csv
To select specific properties while exporting, you can use Select-Object command. Following command only export the properties 'Manager,DisplayName,CompaGet-ADuser -Filter * -Properties Manager,DisplayName,Company -SearchBase "OU=Users,OU=HQ,DC=Max,DC=com" | Select-Object Manager,DisplayName,Company | Export-csv C:\report.csv
You can use the –Filter parameter to filter the objects. The following command will return the user objects which Company set as ‘Expert Exchange’
Get-ADUser -Filter {Company -eq "Expert Exchange"}
To read more about –Filter use following command.
Get-Help about_ActiveDirectory_Filter -Full
Another option to filter the result is to use Where-Object command. Following command will return the user objects which Company set as ‘Expert Exchange’
Get-ADUser –Filter * | Where-Object {$_.Company -eq "Expert Exchange"}
Following command will display all user account which does not have the Company attribute value set.
Get-ADUser –Filter * | Where-Object {$_.Company -eq $null}
The cmdlets also support Ldap filter via the -LdapFilter parameter..
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)