Red Gate forums :: View topic - Check disk space and abort deployment if insufficient
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation

Deployment Manager PowerShell Scripts forum

Check disk space and abort deployment if insufficient

Search in Deployment Manager PowerShell Scripts forum
Post new topic   Reply to topic
Jump to:  
Author Message
james.billings



Joined: 16 Jun 2010
Posts: 1112
Location: My desk.

PostPosted: Thu Jul 04, 2013 11:14 am    Post subject: Check disk space and abort deployment if insufficient Reply with quote

A simple script to check disk space, and fail the deployment if it's below a certain threshold. Add to PreDeploy.ps1


Code:
#Disk Space predeployment check
#Create two variables in Deployment Manager:
# InstallationDriveToCheck = drive to check (with colon) eg. C:
# AbortIfDiskSpaceLessThanMB = amount of space which is needed to succeed, in MB eg. 1024 for 1GB
write-host "***Checking space on drive $InstallationDriveToCheck***"
write-host "Deployment will fail if less than $AbortIfDiskSpaceLessThanMB MB available"
$disk = gwmi win32_volume -Filter "driveletter='$InstallationDriveToCheck'"

[int64]$freespace = ($disk.Freespace) / 1024 / 1024 #convert to MB

if ($freespace -lt $AbortIfDiskSpaceLessThanMB)
{
    write-host "Drive $InstallationDriveToCheck has insufficient disk space! ($freespace MB)"
    exit -1
}
else
{
    write-host "Drive $InstallationDriveToCheck has $freespace MB  free, continuing..."
    exit 0
}
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group