2012-12-10 22 views
0

我正在編寫一個腳本,它將自動從.blg Perfmon日誌中提取數據。從Perfmon中提取主機名與Powershell blg

我已經制定了主要的Import-Counter命令,我將需要使用它來獲取數據,但是我試圖對此進行參數設置,以便我可以爲日誌文件中的每臺計算機執行此操作(無需打開在Perfmon中登錄,這可能需要15分鐘或更多時間,這也是我寫這個腳本的原因),並找出每個主機名是什麼。

腳本我已經完成了這項工作,但它仍然需要一分鐘才能返回我想要的數據,我想知道是否有更簡單的方法來完成此任務,因爲我對Powershell不太熟悉?

這是我有:

$counters = Import-Counter -Path $log_path$logfile -ListSet * | Select-Object paths -ExpandProperty paths 

$svrs = @() 

# for each line in the list of counters, extract the name of the server and add it to the array 
foreach ($line in $counters) { 
    $svrs += $line.split("\")[2] 
} 

# remove duplicates and sort the list of servers 
$sorted_svrs = $svrs | sort -unique 

foreach ($svr in $sorted_svrs) { 
    Write-Host $svr 
} 

我只是打印名字的那一刻,但他們會進入在適當的腳本一個數組,然後我會跑我的導入櫃檯塊與參數化的每個這些主機。

只是想知道是否有更好的方法來做到這一點?

回答

0
$sorted_svrs=Import-Counter "$log_path$logfile" -Counter "\\*\physicaldisk(_total)\% disk time" | %{$_.countersamples.path.split("\")[2]} | sort -Unique