########################################################### # PowerGadgets Chart Data Sample ########################################################### # - Created by Zach Rosenfield # http://sharepoint.microsoft.com/blogs/zach # # WARNING: This is just a sample--do not use against a # live farm without ample testing. # ########################################################### [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") #setup STSADM var $stsadm = "$env:programfiles\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\STSADM.EXE" #Function to get Web Apps function Get-SPWebApplication($name){ $farm = [microsoft.sharepoint.administration.spfarm]::local $webservice = New-Object microsoft.sharepoint.administration.spwebservicecollection($farm) if($name -eq $null){ #return all $webservice | %{$_.WebApplications } | Write-Output }else{ #get one... $webservice | %{$_.WebApplications } | Where{$_.Name -eq $name}| Write-Output } } #Upload Functions function getdestname($filename){"http://sharepointserver:8081/Monitoring%20Images/" + $(split-path -leaf $filename)} function Upload-FileDirectory($dir){ $wc = new-object System.Net.WebClient $wc.Credentials = [System.Net.CredentialCache]::DefaultCredentials dir $dir | % { $uploadname=getdestname $_; $wc.UploadFile($uploadname,"PUT", $_.FullName) } } $global:days = 6; $global:tracker = 0,0,0,0,0,0 $creationDate = { #Get all web applications (or the one specified) Get-SPWebApplication $vars['name'] | %{ $x=""; #Get all site collections $_.Sites | %{ #Store Data if($_.CertificationDate.ToLocalTime() -gt ($(Get-Date).AddDays(-5)) ){ for($i=0;$i -lt $days;$i++){ $x = "FOOBAYR" if($_.CertificationDate.ToLocalTime().ToShortDateString() -eq ($(Get-Date).AddDays(-$i).ToShortDateString()) ){ $global:tracker[$i] += 1; } } } $_.Dispose(); } } for($i=0;$i -lt $days;$i++){ $object = new-object object Add-Member -inputobject $object -membertype NoteProperty -Name Date -Value ($(Get-Date).AddDays(-$i).ToShortDateString()) Add-Member -inputobject $object -membertype NoteProperty -Name Count -Value $tracker[$i] Write-Output $object } } &$creationDate | Out-Chart -size 275,350 -Title "Sites Created (Last 5 Days)" -label Date -values Count -Template "C:\Program Files\PowerGadgets\Templates\BarChartSoftCreation.pgt" -output "C:\MonitoringFiles\Images\CreationDate.png" Upload-FileDirectory "C:\MonitoringFiles\Images"