如何在每个对象之间返回另一行?

问题描述 投票:1回答:1

我正在尝试为我的代码在输出的每一行之间返回多余的一行。我曾尝试在函数的不同位置使用-join“`n”运算符,但它似乎永远无法正常工作。

我不确定应该在哪里放置它。

其当前返回如下:

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

尽管我希望它看起来像这样:

Name: Testie Mctest

UserPrincipalName: [email protected]

etc.

etc.

我确信有一个简单的解决方案,我只是PowerShell的新手。预先感谢。

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"
    }
}

powershell join formatting newline operator-keyword
1个回答
0
投票

尝试在代码中添加write-output ""或写输出“`n”。

© www.soinside.com 2019 - 2024. All rights reserved.