Expand property using hash table and PSObject

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Grant Harrington Grant Harrington 4 months, 3 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #38633
    Profile photo of Grant Harrington
    Grant Harrington
    Participant

    Is it possible to expand a property in a hash table and pass that to a PSObject?

    I'm looking to expand the MemberOf property in an AD Audit report (see bottom example).

    get-aduser grant.harrington -Properties * | select @{n='memberof';e={$_.memberof -join '; '}} | ft -Wrap
    get-aduser grant.harrington -Properties * | select -ExpandProperty MemberOf
            $GetUser = Get-ADUser -SearchBase $MyOU -filter $varName -Properties * #-Credential $DomainCredential
                foreach ($GU in $GetUser)
                    {
                    
                    $ObjAccountReviewResults =[ordered]@{
                        "Full Name"=$GU.CN
                        "First Name"=$GU.GivenName
                        "Initials"=$GU.Initials
                        "Last Name"=$GU.Surname
                        "Display Name"=$GU.DisplayName
                        "Description"=$GU.Description
                        "Office"=$GU.Office
                        "Office Phone"=$GU.OfficePhone
                        "E-Mail Address"=$GU.EmailAddress
                        "REE Web Page"=$GU.wWWHomePage
                        "Login Name"=$GU.UserPrincipalName
                        "SamAccountName"=$GU.SamAccountName
                       "Password Never Expires Setting: " =  $GU.PasswordNeverExpires
                        "Home Drive Letter"=$GU.HomeDrive
                        "Home Directory"=$GU.HomeDirectory
                        "Information"=$GU.info
                        "Title"=$GU.Title
                        "Department (RU)"=$GU.Department
                        "Manager (Supervisor)"=$GU.Manager
                        "Member Of"=$GU.MemberOf
                        "Member Of2" =  -ExpandProperty $GU.MemberOf
                        "Member Of3" = "@{n='$GU.memberof';e={$GU.memberof -join '; '}}"
                        "Distinguished Name" = $GU.DistinguishedName
                        "Account enabled (T/F)"=$GU.Enabled
                        "Created"=$GU.Created
                        "Last Login"=$GU.LastLogonDate
                        "PasswordLastSet"=$GU.PasswordLastSet
                        "Last Bad Password Attempt"=$GU.LastBadPasswordAttempt
                        "Security ID"=$GU.SID
                        "CustomAttribute"=$GU.extensionAttribute1
                        } #end ObjAccountReviewResults
    
                $ObjAccountReview = New-Object -TypeName PSObject -Property $ObjAccountReviewResults
                Write-Output $ObjAccountReview
    
    #38634
    Profile photo of Anthony Stringer
    Anthony Stringer
    Participant

    try this line

    "Member Of" = $GU.MemberOf -join ';'
    
    #38635
    Profile photo of Grant Harrington
    Grant Harrington
    Participant

    That was easy. 🙂

    Thank you, that produced the results I was looking for.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.