-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path1086.ps1
More file actions
40 lines (36 loc) · 1.4 KB
/
Copy path1086.ps1
File metadata and controls
40 lines (36 loc) · 1.4 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
###########################################################################"
#
# NAME: Get-SQLDatabaseFreespace.ps1
#
# AUTHOR: Jan Egil Ring
# EMAIL: jan.egil.ring@powershell.no
#
# COMMENT: Requires SQL Server 2008 Management Studio Express. The script gets free space from the specified SQL Database
# and sends the result to the specified e-mail address.
#
# You have a royalty-free right to use, modify, reproduce, and
# distribute this script file in any way you find useful, provided that
# you agree that the creator, owner above has no warranty, obligations,
# or liability for such use.
#
# VERSION HISTORY:
# 1.0 10.05.2009 - Initial release
#
###########################################################################"
#Add SQL Server 2008 PowerShell snapin
Add-Pssnapin SqlServerProviderSnapin100
#Get free space in specified database
cd SQLSERVER:\SQL\SQL-server-name\Instance-name\Databases
$DB = Get-Item "Database01"
$SpaceAvailable = $DB.SpaceAvailable
$formattedresult = $SpaceAvailable
$result = "{0:#.00}" -f ($SpaceAvailable/1kb)
#Send result to specified e-mail address
$smtpServer = "smtp-server-name"
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "sender@domain.local"
$msg.To.Add("recipient@domain.local")
$msg.Subject = "Free space in Database01"
$msg.Body = "There are $result MB free space in Database01"
$smtp.Send($msg)