Hi,
I'm trying to write a powershell query which finds all active directory users groups matching a certain string, finds the list of all members, and their last logon dates however I'm struggling and would appreciate any help
The issue I'm having is line 21:
because Get-ADGroupMember can't use the lastlogondate object. Can anyone help or have a solution to this?
Thanks
Sam
I'm trying to write a powershell query which finds all active directory users groups matching a certain string, finds the list of all members, and their last logon dates however I'm struggling and would appreciate any help
Code:
Import-Module ActiveDirectory
$Groups = (Get-AdGroup -filter * | Where {$_.name -like "vpn*"} | select name -expandproperty name)
$Table = @()
$Record = [ordered]@{
"Group Name" = ""
"Name" = ""
"Username" = ""
"LastLogonDate" = ""
}
Foreach ($Group in $Groups)
{
$Arrayofmembers = Get-ADGroupMember -identity $Group -Recursive | select name,samaccountname, lastlogondate
foreach ($Member in $Arrayofmembers)
{
$Record."Group Name" = $Group
$Record."Name" = $Member.name
$Record."UserName" = $Member.samaccountname
$Record."LastLogonDate" = $Member.lastlogondate
$objRecord = New-Object PSObject -property $Record
$Table += $objrecord
}
}
$Table | export-csv C:\users\user\Documents\vpngroupoutput.csv -NoTypeInformation
The issue I'm having is line 21:
Code:
Get-ADGroupMember -identity $Group -Recursive | select name,samaccountname, lastlogondate
because Get-ADGroupMember can't use the lastlogondate object. Can anyone help or have a solution to this?
Thanks
Sam