search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Calculating daily bandwidth usage of websites on IIS7.5 with Powershell
Posted in Hosting & IIS7, Windows Powershell | No Comment | 10,994 views | 18/04/2010 12:05

First, you need IIS Log Parser 2.2 to parse log files and calculate daily usage. Then we will get list of websites with Powershell and write bandwidth usages into a file.

Download IIS Log Parser v2.2:

Install IIS Log Parser v2.2. I created a new directory in drive D called LogParser and copied 2 files (logparser.dll and logparser.exe) into that directory. Now let’s see Powershell codes how to use LogParser v2.2 with Powershell.

1
2
3
4
5
6
7
8
9
10
11
12
Import-Module WebAdministration
Websites = Get-Website *
Foreach ($i in $Websites)
{
$Name = $i.Name
$ID = $i.ID
$PhysicalPath = $i.PhysicalPath
$Date = (Get-Date).AddDays(-1).ToString("yyMMdd") + '.log'
$Bandwidth = &'D:\tools\LogParser\LogParser.exe' "Select Div(Sum(sc-bytes),1048576) As Bandwidth From '$PhysicalPath\W3SVC$ID\u_ex$Date'" -q:ON
$Value = "$Name : $Bandwidth"
Add-Content -Path Bandwidth.txt -Value $Value
}

You see how easy it is? But this is just an example. I don’t care about Log Path. You should edit path for your own environment. Have fun!



Leave a Reply