PowerShell: Mario Mett, disk usage.ps1

From ICO wiki
Revision as of 18:11, 26 January 2012 by Mmett (talk | contribs) (Created page with '<source lang="powershell"> <# .SYNOPSIS Skript joonistab C ketta kasutatud ruumi kohta Excelisse sektordiagrammi. NB! Skript ei tööta eestikeelsete keeleseatetega (ht…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<source lang="powershell">

<# .SYNOPSIS

   Skript joonistab C ketta kasutatud ruumi kohta Excelisse sektordiagrammi. 
   NB! Skript ei tööta eestikeelsete keeleseatetega (http://support.microsoft.com/default.aspx?scid=kb;en-us;320369)

.NOTES

   Autor: Mario Mett
  1. >
  1. Loome uue Exceli objekti, workbook'i ja worksheet'i.

$excel = New-Object -ComObject Excel.Application $excel.visible = $true $workbook = $excel.Workbooks.Add() $worksheet = $workbook.Worksheets.Add() $worksheet1 = $workbook.worksheets.Item(1)

  1. Küsime C: ketta vaba ruumi ja kogu suuruse.

$disk = Get-WMIObject Win32_LogicalDisk -filter "DeviceID='C:'" | select FreeSpace,Size

[long]$size = $disk.Size; [long]$freespace = $disk.FreeSpace; $used = $size - $freespace

  1. Täidame esimese veeru graafiku legendidega

$worksheet.cells.item(1,2)="Free" $worksheet.cells.item(1,3)="Used"

  1. Täidame teise veeru graafku pealkirja ja vajalike väärtustega

$worksheet.cells.item(2,1)="C: disk usage" $worksheet.cells.item(2,2)=$freespace $worksheet.cells.item(2,3)=$used

  1. Määrame graafiku tüübi ja kust info võetakse.

$range = $worksheet1.UsedRange $range.EntireColumn.AutoFit() $workbook.charts.add() $workbook.ActiveChart.chartType=[microsoft.office.interop.excel.xlChartType]::xlPie $workbook.ActiveChart.SetSourceData($range)

  1. Salvestame faili

$workbook.SaveAs("C_disk_usage.xlsx")