How do I return another line between each object?

2020-05-23 powershell join formatting newline operator-keyword

I am trying to return an extra line between each line of the output for my code. I have tried using the -join "`n" operator in different places in the function, but it never seems to work.

I'm unsure as to where exactly I should put it.

It currently returns like this:

Name: Testie Mctest
UserPrincipalName: [email protected]
etc.
etc.

Though i'd like it to look like this:

Name: Testie Mctest

UserPrincipalName: [email protected]

etc.

etc.

I'm sure there's an easy solution to this, i'm just new to PowerShell. Thanks in advance.

function Get-ADUserInfo
{
    param
    (
        [Parameter (mandatory = $true, Position = 0, ValueFromPipeline = $true)]
        [ValidateLength (3, 10)]
        [String]$Username
    )

    #create an array for a neater script
    $ADUserproperties =
    @(
        "Name"
        "UserPrincipalName"
        "Description"
        "Enabled"
        "CanonicalName"
        "Created"
        "pager"
        "LockedOut"
        "PasswordExpired"
        "PasswordLastSet"
        "BadLogonCount"
        "badPwdCount"
        "LastBadPasswordAttempt"
        "LastLogonDate"
    )

    try
    {
        Get-ADUser -Identity $Username -Properties $ADUserproperties | select $ADUserproperties

        Get-ADPrincipalGroupMembership -Identity $Username | select-object Name -ExpandProperty Name | Sort-Object -Descending | Out-GridView -Title "$($Username)'s AD Groups:"

    }

    catch
    {
        "Could not find '$($Username)' in Active Directory"
    }
}

Answers

Related