6

I'm trying to write a script for Powershell that will display the date/time of last login and date/time of last password change for every user and separate the data according to their Organizational Unit within Active Directory.

I'm getting a number of errors, including one that says Get-ADUser isn't even recognized as a command. Any thoughts? Here's my script:

$my=get-credential

get-aduser -filter "name -like * -searchbase 'OU=students,OU=Users,OU=GBNetworkLabs,DC=gbnetworklabs,DC=local'"
-properties * -server gbnetworklabs.local -credential $my | select -property name, lastlogondate, passwordlastset

I've also tried import-module activedirectory but get errors with that too.

Here are some of the parameters I've been given:

Users='OU=Students,OU=Users,OU=GBNetworkLabs,DC=gbnetworklabs,DC=local' Servers='OU=Powershell,OU=VDI,OU=GBNetworkLabs,DC=gbnetworklabs,DC=local'

Any and all help is appreciated! Thank you!

PandaRasta
  • 321
  • 4
  • 15
ITKev
  • 59
  • 1
  • 1
  • 5
  • 1
    Before you can run AD cmdlets you must, as you've shown, run `import-module activedirectory` - what error are you running into when running this? – Matthew Dec 06 '19 at 16:48
  • 3
    The ActiveDirectory PowerShell module is not installed by default. If you're on a Server OS, it's a feature that can be installed from Server Manager. On Client OSes, it is part of a package called RSAT (Remote Server Administration Tools) and may either be a separately downloadable installer or a Windows optional feature depending on the OS version. – Ryan Bolger Dec 06 '19 at 16:48
  • Hi Matthew, this is the error I keep getting:```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``` – ITKev Dec 07 '19 at 03:19
  • Thanks for the help Ryan, I'll see if I can use RSAT! – ITKev Dec 07 '19 at 03:57

1 Answers1

17

If you need the Active Directory Powershell cmdlets on Windows 10 later verisons they can be installed as follows:

Get-WindowsCapability -Online | Where-Object {$_.Name -like "*ActiveDirectory.DS-LDS*"} | Add-WindowsCapability -Online
Scepticalist
  • 3,737
  • 1
  • 13
  • 30