What does it do?
The script will create a report of all Web Applications and the associated Content Databases.
It will tell you how big each Content Database is in GB. The result will be saved in a .txt file. Optionally, you can send this .txt as an attachment in an e-mail.
If you are using this script to mail the report, you might want to add a body to the e-mail, so you can make it look better, but this is not included with the current script.
How to use it
I designed the script so it is easy to schedule as a task. Before you go ahead and schedule it in the task scheduler, you have to add values to some optional and required parameters, For instance, if you want to e-mail this .txt file, you should add at least a SMTP Server, subject, the mail from address and the send to address.
#Get SharePoint Content database sizes
#Variables that you can change to fit your environment
$webapps = Get-SPWebApplication
Scheduling the script
Save the script (In my example: C:\Install\Get-SPContentDatabaseSize.ps1)
Start the Task scheduler: Start –> Run: taskschd.msc
Create a new task:
– Make sure the account running the task has sufficient permissions to access the databases
– “Run whether user is logged on or not” should be checked.
– Run with highest privileges has to be checked.
The triggers can be set to your requirements, in this example I scheduled the task weekly at 6PM.
To run a PowerShell script as a scheduled task, you cannot simply add the C:\Install\Get-SPContentDatabaseSize.ps1 in the “Program/script” field.
You should do the following:
Add arguments (optional): -Command C:\Install\Get-SPContentDatabaseSize.ps1
Click OK and enter the password for the account that is running the scheduled task, and VOILA.