Hello and thank you for your anticipated help with this.
Pretty new at Powershell because I was good at the old ways.
Doing my best to stop going back to the old, familiar out of date ways so here goes.
Below is a script that I’ve put together from things found on the interwebs.
It walks through a group and subgroups for members and displays as required.
It’s working as designed but new requirements from the client have come forth
req 1: don’t show disabled users
req 2: don’t show accounts with no defined expiration date
When I attempt to have it skip disabled users with (below) I get an error.
`Get-ADUser -filter {enabled -eq $true} -Prop Description…
Any help with this as well as not displaying the hundreds of users accounts that don’t have the account expiry set would be greatly appreciated.
function Get-ADNestedGroupMembers {
[cmdletbinding()]
param (
[String] $GroupName
)
import-module activedirectory
$Members = Get-ADGroupMember -Identity $GroupName
$members | % {
if($.ObjectClass -eq “group”) {
Get-ADNestedGroupMembers -GroupName $.distinguishedName
} else {
return $_.distinguishedname
}
}
}
import-module activedirectory
Get-ADNestedGroupMembers -groupname “group name here” |
`Get-ADUser -Prop Description,samAccountName,AccountExpirationDate, mail, LastLogoff, lastLogonTimestamp, company |
`Select-Object Name,samAccountName,AccountExpirationDate, mail, LastLogoff, @{N=‘LastLogonTimestamp’; E={[DateTime]::FromFileTime($_.LastLogonTimestamp)}}, company |
`Sort-Object AccountExpirationDate -descending |
#`Format-Table -property * -AutoSize |
`ConvertTo-HTML | Out-File C:\Temp\working\AccountExpiry.htm