forked from mubix/PowerShell-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Collect-TableSizes.ps1
38 lines (29 loc) · 1.05 KB
/
Collect-TableSizes.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Collect-TableSizes.ps1
param(
$SQLServer = 'XSQLUTIL19',
$Database = 'Chevron_ES27060'
)
# Keep this next part on one line… This gets your objects to put in the chart
$BigTables= DIR SQLSERVER:\SQL\$SQLServer\DEFAULT\Databases\$Database\Tables | sort-Object -Property RowCount -desc | select-Object -First 20
$excel = new-object -comobject excel.application
$excel.visible = $true
$chartType = "microsoft.office.interop.excel.xlChartType" -as [type]
$workbook = $excel.workbooks.add()
$workbook.WorkSheets.item(1).Name = "BigTables"
$sheet = $workbook.WorkSheets.Item("BigTables")
$x = 2
$sheet.cells.item(1,1) = "Schema Name"
$sheet.cells.item(1,2) = "Table Name"
$sheet.cells.item(1,3) = "RowCount"
Foreach($BigTable in $BigTables)
{
$sheet.cells.item($x,1) = $BigTable.Schema
$sheet.cells.item($x,2) = $BigTable.Name
$sheet.cells.item($x,3) = $BigTable.RowCount
$x++
}
$range = $sheet.usedRange
$range.EntireColumn.AutoFit()
$workbook.charts.add() | Out-Null
$workbook.ActiveChart.chartType = '-4100'
$workbook.ActiveChart.SetSourceData($range)