Get-ADInfo.psm1

<#
 .Synopsis
  Cmdlet for gathering AD User information.
 
 .Description
  Get-UserInfo lists important information about Active Directory Users. Includes membership information.
 
 .Parameter Name
  Name of an AD User.
 
 .Example
   # List information about a group
   Get-UserInfo -Name Administrator
 
 .Example
   # List information about all groups
   Get-UserInfo -Name *
 
 .Link
    
#>

function Get-UserInfo{
    param($Name)
    if($Name -eq "*"){
        $User = Get-ADUser -Filter * -properties *
    }else{
        $User = Get-ADUser $Name -properties *
    }
    foreach($x in $User){
        $MemberOf = (Get-ADUser $x -Properties *).MemberOf | %{ ($_ -split "," -like "CN=*" -split "=")[1]}
        $Write = @"
--------------------------------------------------------------
SAM: {0}
SID: {1}
CN: {2}
DN: {3}
CREATED: {4}
CHANGED: {5}
HOME: {6}
 
AUTHENTICATION STATS
LAST LOGON: {7}
LAST FAILED LOGON: {8}
LOGON COUNT: {9}
LOCKED OUT: {10}
PASS LAST SET: {11}
PASS EXPIRED: {12}
PASSWORD NEVER EXPIRES: {13}
 
        MEMBER OF
        -------------------------------
"@
 -f $x.SamAccountName, $x.SID, $x.CN, $x.DistinguishedName, $x.Created, $x.WhenChanged, $x.HomeDirectory, $x.LastLogonDate,
      $x.LastBadPasswordAttempt, $x.LogonCount, $x.LockedOut, $x.PasswordLastSet, $x.PasswordExpired, $x.PasswordNeverExpires
      Write-Host $Write
      if($MemberOf -gt 0){
        foreach($x in $MemberOf){
            write-host @"
        $x
"@
       
        }
      }else{
        Write-Host @"
        NONE
"@

      }
      Write-Host 
    }
}

<#
 .Synopsis
  Cmdlet for gathering AD Group information.
 
 .Description
  Get-GroupInfo lists important information about Active Directory Groups. Includes membership information.
 
 .Parameter Name
  Name of an AD Group.
 
 .Example
   # List information about a group
   Get-GroupInfo -Name Administrators
 
 .Example
   # List information about all groups
   Get-GroupInfo -Name *
 
 .Link
    
#>

function Get-GroupInfo{
    param($Name)
    if($Name -eq "*"){
        $Group = Get-AdGroup -Filter * -Properties *
    }else{
        $Group = Get-ADGroup "$Name" -Properties *
    }
    foreach($x in $Group){
        $GroupMembers = Get-ADGroupMember $x.Name | % SamAccountName
        $MemberOf = (Get-AdGroup $x.Name -properties *).MemberOf 
        $Write = @"
--------------------------------------------------------------
GROUP: {0}
SID: {1}
DN: {2}
CREATED: {3}
CHANGED: {4}
DESCRIPTION: {5}
 
        MEMBER OF
        -------------------------------
"@
 -f $x.CN, $x.SID, $x.DistinguishedName, $x.Created, $x.WhenChanged, $x.Description
        Write-Host $Write
        if($MemberOf -gt 0){
                    foreach($x in $MemberOf){
                        $MemberSplit = ($x -split "," -like "CN=*" -split "=")[1]
                        write-host @"
        $MemberSplit
"@

                    }
        }else{
            write-host @"
        NONE
"@

        }
        Write-Host @"
         
        MEMBERS
        -------------------------------
"@

        if($GroupMembers -gt 0){
            foreach($x in $GroupMembers){
            write-Host @"
        $x
"@

            }
        }else{
            write-Host @"
        NONE
"@

        }
        $GroupMembers = $Null
        $MemberOf = $Null
        Write-Host
    }
}
<#
 .Synopsis
  Cmdlet for gathering AD Computer information.
 
 .Description
  Get-ADComputerInfo lists important information about Active Directory Computers. Includes membership and address information.
 
 .Parameter Name
  Name of an AD Computer.
 
 .Example
   # List information about a computer
   Get-ADComputerInfo -Name WIN-3JT8OEGQT3D
 
 .Example
   # List information about all computers
   Get-ADComputerInfo -Name *
 
 .Link
    
#>

function Get-ADComputerInfo{
    param($Name)
    $ErrorActionPreference = 'SilentlyContinue'
    if($Name -eq "*"){
        $Computer = Get-ADComputer -filter * -properties *
        }else{
            $Computer = Get-ADComputer -Identity $Name -properties *
        }
    foreach($x in $Computer){
        Try{
                # $Zone = Get-ADComputer -Identity $x.Name -Property CanonicalName |select -ExpandProperty CanonicalName | %{($_ -split "/")[0]}
                # $ComputerIP = (Get-DnsServerResourceRecord -ZoneName $Zone -Name $x.Name -RRType A).RecordData.IPv4Address.IPAddressToSTring
                $ComputerIP = Resolve-DnsName $x.Name -ErrorAction Stop -ErrorVariable e
            }catch{
                $ComputerIP = @{IP4Address=((($e -split "Stop" -like "*DNS*" -split "at")[0]).Trim(": "));IP6Address=((($e -split "Stop" -like "*DNS*" -split "at")[0]).Trim(": "))}
            }
        $Write = @"
--------------------------------------------------------------
NAME: {0}
OPERATING SYSTEM: {1}
SID: {2}
DN: {3}
CREATED: {4}
CHANGED: {5}
ENABLED: {6}
 
DNS HOST NAME: {15}
IPV4: {7}
IPV6: {8}
 
AUTHENTICATION STATS
LAST LOGON: {9}
LAST FAILED LOGON: {10}
LOCKED OUT: {11}
PASS SET: {12}
PASS EXPIRED: {13}
PASSWORD NEVER EXPIRES: {14}
 
        MEMBER OF
        -------------------------------
"@
 -f $x.Name, $x.OperatingSystem, $x.SID, $x.DistinguishedName, $x.Created, $x.WhenChanged, $x.Enabled,
              $ComputerIP.IP4Address, $ComputerIP.IP6Address, $x.LastLogonDate, $x.LastBadPasswordAttempt,
              $x.LockedOut, $x.PasswordLastSet, $x.PasswordExpired, $x.PasswordNeverExpires, $x.DNSHostName
        Write-Host $Write
        $PrimaryGroup = (($x).PrimaryGroup -split "," -like "CN=*" -split "=")[1]
        $MemberOf = (($x).MemberOf -split "," -like "CN=*" -split "=")[1]
        $ManagedBy = (($x).ManagedBy -split "," -like "CN=*" -split "=")[1] 
        Write-Host @"
        $PrimaryGroup
        $MemberOf
 
        MANAGED BY
        -------------------------------
        $ManagedBy
"@

        Write-Host 
    }
}