Author Posts

February 21, 2014 at 10:53 am

I currently have a one liner that uses get-aduser to query for users that have not logged in and then I do some filtering. I have managed to get the memberof attribute to display correctly in a csv file. I would like to be able to sort on specific group membership. I orginally thought about splitting group membership into separate columns but I thought this might result in inconsistent results. How would I go about creating some custom columns in my csv file and doing boolean evaluation of specific group membership? If any more experienced powershell users have some better ideas than this, I would appreciate any help. I have about five groups that I want to be able to sort with.

$Date = (Get-date).AddMonths(-26).Date
get-aduser -Filter {(memberOf -ne "DN of group name")} -Properties DisplayName,SamAccountName,GivenName,Surname,StreetAddress,State,LastLogonDate,Created,EmailAddress,memberof,lastlogontimestamp -SearchBase "targetOU" -SearchScope Subtree -Server FQDN of server| Select DisplayName,SamAccountName,GivenName,Surname,StreetAddress,State,LastLogonDate,Created,EmailAddress,@{name='MemberOf'; expression={ ($_.MemberOf | ForEach { ($_ -split ',')[0] -replace 'CN=',"}) -join ','}},@{N='LastLogonTimestamp'; E={[DateTime]::FromFileTime($_.LastLogonTimestamp)}} | where-object {$_.lastlogontimestamp -lt $Date} | export-csv file path -NoTypeInformation

February 26, 2014 at 7:58 am

I figured something out on this, no help needed.

February 27, 2014 at 8:17 am

Jesse,
how did you manage to solve your issue?
Thanks