以下是我參考網路上寫出來的語法
但是有個問題我無法排除
一台虛擬機可能有scsi0:0 或ide0:0
我無法單獨選擇我要的類型合併顯示
不知道語法哪裡需要修改
麻煩 指導我一下 感激不盡
I learn from the Internet to write following script
But there is a problem I can not solve
A virtual machine may use scsi0: 0 or ide0: 0
Can not single type combinations to display
I do not know where the script need to be modified
Please tell me how to modify the script
Thank you very much
============================================
So if I understand correctly you want something like this in the output
VMName VM1 VM2
CPU Usage Avg 17 28
CPU Usage Avg MHz 732 453
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Would love to help you, but I'm afraid something went wrong during the copy of the script.
I get a bunch of what I think are Chinese characters in there
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If your question, I guess, is how you can include metrics for ide0:0 and scsi0:0 in the output, there are several ways of doing that.
The simplest is to replace this line
$stats | where {$_.Instance -eq "scsi0:0"}| Group-Object -Property Instance | %{
with something like this
$stats | where {"ide0:0","scsi0:0" -contains $_.Instance}| Group-Object -Property Instance | %{
If I completely misunderstood the question please let me know
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
1 , yes u got me
2 , i am so sorry that i posted wrong script , i forgot to add to some parameters.andd i changed chinese to Eng ^^
3. the script you posted i tried before ,and it show nothing.
4.i will upload script with Successful execl file in rar .
5.thanks anyway
show nothing
=======================================
if i move red line it run well
===============================================
$entity = Get-Vm | where {$_.NAME -eq "eBOOK"}
$APP = @()
$runday = ((get-date).day -1)
$day = (get-date).day
$runmonth = (get-date).month
$runyear = (get-date).year
$metrics = "cpu.usage.average","cpu.usagemhz.average","cpu.ready.summation","cpu.capacity.entitlement.average","cpu.corecount.contention.average","mem.usage.average","mem.swapinRate.average","mem.swapoutRate.average","mem.vmmemctl.average","mem.consumed.average","mem.overhead.average","mem.capacity.entitlement.average","mem.capacity.usage.average","disk.usage.average","net.usage.average"
$savepath = "c:\" + $entity + "-" + "$runyear" + "-" + "$runmonth" + "-" +"$runday" + ".csv"
$start = "$runmonth"+"/"+"$runday"+"/"+"$runyear"
$finish = "$runmonth"+"/"+"$day"+"/"+"$runyear"
$stats = Get-Stat -Entity $entity -Stat $metrics -Start $start -Finish $finish
$stats | Group-Object -Property Instance | where {$_.Timestamp -ne "",$_.value -ne ""} | %{
$_.Group | Group-Object -Property {$_.Timestamp} | %{
$row = "" | Select "time","cpu_usage_average","cpu_usagemhz_average","cpu_ready_summation","cpu_capacity_entitlement_average","cpu_corecount_contention_average","mem_usage_average","mem_swapinRate_average","mem_swapoutRate_average","mem_vmmemctl_average","mem_consumed_average","mem_overhead_average","mem_capacity_entitlement_average","mem_capacity_usage_average","disk_usage_average","net_usage_average"
$row."time" = $_.Group[0].Timestamp
$row."cpu_usage_average" = $_.Group[0].value
$row."cpu_usagemhz_average" = $_.Group[1].value
$row."cpu_ready_summation" = $_.Group[2].value
$row."cpu_capacity_entitlement_average" = $_.Group[3].value
$row."cpu_corecount_contention_average" = $_.Group[4].value
$row."mem_usage_average" = $_.Group[5].value
$row."mem_swapinRate_average" = $_.Group[6].value
$row."mem_swapoutRate_average" = $_.Group[7].value
$row."mem_vmmemctl_average" = $_.Group[8].value
$row."mem_consumed_average" = $_.Group[9].value
$row."mem_overhead_average" = $_.Group[10].value
$row."mem_capacity_entitlement_average" = $_.Group[11].value
$row."mem_capacity_usage_average" = $_.Group[12].value
$row."disk_usage_average" = $_.Group[13].value
$row."net_usage_average" = $_.Group[14].value
$APP += $row
}
}
$APP |sort time
The filtering on the instances is happening too soon. At that time you have metrics for all the counetr types you specified.
Meaning that this where-clause will throw away all the metrics that do have a ide0:0 or scsi0:0 instance.
The grouping should be organised in the order that you want your results: so first group on Timestamp and then on Entity (the VM name).
In the resulting group you will now have metrics for all the counters your specified on the Get-Stat cmdlet.
For the disk.usage.average counter, what do you want to include in the report ?
Only the values for IDE0:0 or SCSI0:0 ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i want the values for SCSI0:0 in that file ^^
another question how can i change the file form like below ....
A , B , C
1 , 2 , 3
4 , 5 , 6
i want to transpose rows into columns like
A , 1 , 4
B , 2 , 5
C, 3 , 6
plz help me thank ^^
So if I understand correctly you want something like this in the output
VMName VM1 VM2
CPU Usage Avg 17 28
CPU Usage Avg MHz 732 453
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The attached script will produce the results you are looking for.
But for the transpose part I would still need some further clarification.
The resulting CSV, 1 CSV per powered on VM, from this script looks something like this
Is this the table you want to transpose ?
In other words the result would look like this
Time | 20/04/13 00:30 | 20/04/13 01:00 | 20/04/13 01:30 | |
---|---|---|---|---|
cpu_usage_average | 15.9 | 17.3 | 12.3 | |
| 872 | 889 | 855 | |
| 7530 | 8142 | 7211 |
Is that what you want ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
DEAR LucD
Something happens at home , I'm so sorry.to keep you waiting so many days,
Sorry, but I'm not sure I understand what you are trying to do.
My script creates 1 CSV file per VM.
Are you trying to store the results from all VMs in 1 file ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Dear LucD
Sorry,I did not explain well , my english not well ^^
I am using a Chinese system,so i used your script and modify some place. like red line and than it could make i want 1 CSV file per VM.
thanks a lot ^^
but still have one issue with blue line ,when folder exist it show the folder already exist , if the folder already exist ,i want to it will skip to create folder action , but still creat CSV file ,please tell me where Should modify it
====================================================
Try it like this
New-Item -Path "C:\1\$($entity)" -ItemType "directory"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference