Repository navigation
Expand file tree
/
Copy path01_Server_Storage.ps1
More file actions
147 lines (126 loc) · 3.65 KB
/
Copy path01_Server_Storage.ps1
File metadata and controls
147 lines (126 loc) · 3.65 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<#
.SYNOPSIS
Gets the Windows Volumes on the target server
.DESCRIPTION
Writes the windows Volumes out to the "01 - Server Storage" folder
One file for all volumes
This is to know what drive and mount-points the server has
.EXAMPLE
01_Server_Storage.ps1 localhost
.EXAMPLE
01_Server_Storage.ps1 server01 sa password
.Inputs
ServerName, [SQLUser], [SQLPassword]
.Outputs
HTML File
.NOTES
.LINK
https://github.com/gwalkey
#>
[CmdletBinding()]
Param(
[string]$SQLInstance='localhost',
[string]$myuser,
[string]$mypass
)
# Load Common Modules and .NET Assemblies
try
{
Import-Module ".\SQLTranscriptase.psm1" -ErrorAction Stop
}
catch
{
Throw('SQLTranscriptase.psm1 not found')
}
LoadSQLSMO
# Init
Set-StrictMode -Version latest;
[string]$BaseFolder = (Get-Item -Path ".\" -Verbose).FullName
Write-Host -f Yellow -b Black "01 - Server Storage"
Write-Output("Server: [{0}]" -f $SQLInstance)
# Output folder
$fullfolderPath = "$BaseFolder\$sqlinstance\01 - Server Storage\"
if(!(test-path -path $fullfolderPath))
{
mkdir $fullfolderPath | Out-Null
}
# Split out servername only from named instance
$WinServer = ($SQLInstance -split {$_ -eq "," -or $_ -eq "\"})[0]
# Credit: https://sqlscope.wordpress.com/2012/05/05/
$VolumeTotalGB = @{Name="VolumeTotalGB";Expression={[Math]::Round(($_.Capacity/1GB),2)}}
$VolumeUsedGB = @{Name="VolumeUsedGB";Expression={[Math]::Round((($_.Capacity - $_.FreeSpace)/1GB),2)}}
$VolumeFreeGB = @{Name="VolumeFreeGB";Expression={[Math]::Round(($_.FreeSpace/1GB),2)}}
# Let WMI errors be trapped
try
{
$VolumeArray = Get-WmiObject -Computer $WinServer Win32_Volume -ErrorAction stop| sort-object name
if ($?)
{
Write-Output "Good WMI Connection"
}
else
{
$fullfolderpath = "$BaseFolder\$SQLInstance\"
if(!(test-path -path $fullfolderPath))
{
mkdir $fullfolderPath | Out-Null
}
echo null > "$fullfolderpath\01 - Server Storage - WMI Could not connect.txt"
Write-Output "WMI Could not connect"
Set-Location $BaseFolder
Throw("WMI Could not connect")
}
}
catch
{
$fullfolderpath = "$BaseFolder\$SQLInstance\"
if(!(test-path -path $fullfolderPath))
{
mkdir $fullfolderPath | Out-Null
}
echo null > "$fullfolderpath\01 - Server Storage - WMI Could not connect.txt"
Write-Output "WMI Could not connect"
Set-Location $BaseFolder
exit
}
# HTML CSS
$head = "<style type='text/css'>"
$head+="
table
{
Margin: 0px 0px 0px 4px;
Border: 1px solid rgb(190, 190, 190);
Font-Family: Tahoma;
Font-Size: 9pt;
Background-Color: rgb(252, 252, 252);
}
tr:hover td
{
Background-Color: rgb(150, 150, 220);
Color: rgb(255, 255, 255);
}
tr:nth-child(even)
{
Background-Color: rgb(242, 242, 242);
}
th
{
Text-Align: Left;
Color: rgb(150, 150, 220);
Padding: 1px 4px 1px 4px;
}
td
{
Vertical-Align: Top;
Padding: 1px 4px 1px 4px;
}
"
$head+="</style>"
$RunTime = Get-date
Write-Output('{0} Volumes found' -f @($VolumeArray).Count)
$myoutputfile4 = $FullFolderPath+"\Server_Storage_Volumes.html"
$myHtml1 = $VolumeArray | select Name, Label, FileSystem, DriveType, $VolumeTotalGB, $VolumeUsedGB, $VolumeFreeGB, BootVolume, DriveLetter, BlockSize | `
ConvertTo-Html -Fragment -as table -PreContent "<h1>Server: $SqlInstance</H1><H2>Storage Volumes</h2>"
Convertto-Html -head $head -Body "$myHtml1" -Title "Storage Volumes" -PostContent "<h3>Ran on : $RunTime</h3>" | Set-Content -Path $myoutputfile4
# Return To Base
set-location $BaseFolder