使用powershell将数组结果导出到csv

时间:2016-11-03 16:49:25

标签: powershell

我正在使用Citrix XenApp sdk开发PowerShell脚本。我想要做的是使用一个citrix cmdlet获取以下值;加载,用户计数和服务器计数(使用另一个cmdlet)并导出到csv。

我创建了一个csv文件,其中包含我要查询的传递组的名称,因此我通过调用几个citrix cmdlet导入该csv并启动我的阵列:

# Add Citrix XenApp sdk
Add-PSSnapin Citrix.*.Admin.V*
# Define Dashboard Server Name as well as import the Delivery Group csv file.
$DashboardServer = "server.name"
$delivery_group_csv = Import-Csv \\$DashboardServer\path_to_file\file.csv -Delimiter ","
# extract citrix loads per delivery group as well as Session counts for each  delivery group
foreach($silo in $delivery_group_csv) {
                            $DeliveryGroupName = $silo.DeliveryGroupName
                            $LoadIndex = Get-BrokerMachine -DesktopGroupName $DeliveryGroupName
                            $SiloLoad = ($LoadIndex | Measure-Object 'LoadIndex' -Sum).Sum/1000
                            $UserCount = ($LoadIndex | Measure-Object 'SessionCount' -Sum).Sum
                            $ServerCount = Get-BrokerDesktopGroup -Name $DeliveryGroupName
                            $DG_servercount = ($ServerCount).TotalDesktops

Write-Host $DeliveryGroupName "- Load" $SiloLoad"%" " - Servercount" $DG_servercount "- " Total Users" - " $UserCount | Export-Csv -Path \\$DashboardServer\path_to_save\new_file.csv -Append -Encoding UTF8 -NoTypeInformation

问题是当它被导出到csv时我只得到一个空白的csv文件。我对powershell很新,并尝试了各种各样的东西,但完全不知道让它发挥作用。任何帮助将不胜感激。

0 个答案:

没有答案