具有已分配组的Citrix应用程序列表

时间:2016-06-07 19:20:29

标签: powershell

以下脚本为我提供了我想要的列表,但我需要将输出保存到文件中:

asnp citrix*
$apps = Get-BrokerApplication -MaxRecordCount 10000 -AdminAddress  khonemdc75ddc01;
$apps | ForEach-Object { 
    $array = $_.AssociatedDesktopGroupUids
    foreach ($element in $array) {
        $policy = Get-BrokerAccessPolicyRule –DesktopGroupUid $element -AllowedConnections NotViaAG
        write-host "Application: " $_.ApplicationName 
        if ($_.AssociatedUserNames) 
        {
            write-host "Users configured  using Visibility:" $_.AssociatedUserNames
            write-host '--------------------'
        }  
        else
        { 
            write-host "Users with access inherited from DG:"
            $policy.IncludedUsers;  
            write-host '--------------------'
        }
    }
}

2 个答案:

答案 0 :(得分:0)

如果使用Write-Host cmdlet,则无法将输出传递给文件 - 只需将字符串写入管道即可。要保存输出,可以使用Out-File cmdlet:

asnp citrix*
$apps = Get-BrokerApplication -MaxRecordCount 10000 -AdminAddress  khonemdc75ddc01;
$apps | ForEach-Object { 
    $array = $_.AssociatedDesktopGroupUids
    foreach ($element in $array) {
        $policy = Get-BrokerAccessPolicyRule –DesktopGroupUid $element -AllowedConnections NotViaAG
        "Application: $_.ApplicationName" 
        if ($_.AssociatedUserNames) 
        {
            "Users configured  using Visibility: $_.AssociatedUserNames" 
            '--------------------'
        }  
        else
        { 
            "Users with access inherited from DG: $policy.IncludedUsers;"
            '--------------------'
        }
    }
} | Out-File -FilePath 'your_file.txt'

答案 1 :(得分:0)

使用write-output代替write-host,最后将其通过管道传递到末尾> c:\ test.txt