2016-11-27 88 views
1

我試圖輸出Skype響應組隊列的不同屬性以用於文檔目的。在for循環中顯示來自多個變量的輸出

我想NameTimeoutThresholdTimeoutActionTimeouturiOverflowThresholdOverflowActionOverflowCandidate在第1行一個.csv文件頭,然後輸出到各列從行中輸入2.

我曾嘗試下面,但格式非常糟糕,標題不斷重複。有人可以幫忙嗎?

也嘗試在HTML中獲取輸出,但沒有運氣。

$p = Get-CsRgsQueue | Where-Object {$_.Name -like "IPL*"} | Select-Object Name 

foreach ($Name in $p) 
{ 
    $q = Get-CsRgsQueue -Name "$Name" 
    $N = $q.Name 
    $TT = $q.TimeoutThreshold 
    $TA = $q.TimeoutAction.Action 
    $TAU = $q.TimeoutAction.uri 
    $OF = $q.OverflowThreshold 
    $OFA = $q.OverflowAction 
    $OFC = $q.OverflowCandidate 

    $out = New-Object PSObject 
    $out | Add-Member NoteProperty QueueName $N 
    $out | Add-Member NoteProperty Timeout $TT 
    $out | Add-Member NoteProperty TimeoutAction $TA 
    $out | Add-Member NoteProperty TransferURI $TAU 
    $out | Add-Member NoteProperty OverflowThreshhold $OF 
    $out | Add-Member NoteProperty OverflowAction $OFA 
    $out | Add-Member NoteProperty OverflowCandidate $OFC 

    $out | FT -AutoSize | Export-Csv C:\abc.csv -Append 
} 
+0

你有省略'| FT -AutoSize'在最後一行。 –

+0

要整理它,你可以爲你的屬性使用一個散列表,它被稱爲splatting。希望格式化看起來不錯。 EDITED *** Grr,抱歉下面的格式。 –

+0

foreach($ name in $ P) $ properties = @ {$ q = get-csrgsqueue -name「$ Name」 $ N = $ q.Name $ TT = $ q.TimeoutThreshold $ TA = $ q。 TimeoutAction.Action $ TAU = OF = $ q.OverflowThreshold $ OFA = $ q.OverflowAction $ OFC = $ q.OverflowCandidate $ q.TimeoutAction.uri $} 新物體-TypeName psobject -Property $屬性 –

回答

1

下面我都試過了,但格式是真的不好, 不斷重複的頭。有人可以幫忙嗎?

那是因爲你通過FT -AutoSizeFormat-Table -AutoSize)管你的對象 - 永遠只能使用Format-*的cmdlet當你要告訴/你的數據。

您還可以通過只調用Get-CsRgsQueue一次,管道傳輸到ForEach-Object並最終構建對象屬性哈希表節省時間:馬蒂亞斯·耶森的

Get-CsRgsQueue | Where-Object {$_.Name -like "IPL*"} | ForEach-Object { 
    New-object psobject -Property @{ 
     QueueName   = $_.Name 
     Timeout   = $_.TimoutThreshold 
     TimeoutAction  = $_.TimeoutAction.Action 
     TransferURI  = $_.TimeoutAction.Uri 
     OverflowThreshhold = $_.OverflowThreshold 
     OverflowAction  = $_.OverflowAction 
     OverflowCandidate = $_.OverflowCandicate 
    } 
} |Export-Csv c:\abc.csv -NoTypeInformation 
-2

簡短的解決方案

Get-CsRgsQueue | where Name -like "IPL*" | %{ 
    [pscustomobject] @{ 
    QueueName   = $_.Name 
    Timeout   = $_.TimoutThreshold 
    TimeoutAction  = $_.TimeoutAction.Action 
    TransferURI  = $_.TimeoutAction.Uri 
    OverflowThreshhold = $_.OverflowThreshold 
    OverflowAction  = $_.OverflowAction 
    OverflowCandidate = $_.OverflowCandicate 
    } 
} | Export-Csv C:\result.csv -NoType