Posts

Showing posts with the label DiskSpace

Get disk space warnings through PowerShell

Image
Credits Susan NYC I use powershell scripts for disk free space monitoring on servers. Following are the task performed by the script: Clears the content of D:\lowdisk.txt. Adds required headers to D:\lowdisk.txt. Checks through all drives if free disk space is less than specified threshold. If a disk has free space less than threshold then adds info to D:\lowdisk.txt. Mails to users the contents of the  D:\lowdisk.txt if any disk is having free space less than threshold. To know how to execute the PowerShell scripts go to Executing a PowerShell script . Following is the code for the script. You can schedule it using windows scheduler. #Modify the below threshold value as required. It represents the minimum percent of free disk space required. $threshold = 10 #Add the recipients below. Example $To="user1@mail.com", "user2@mail.com", "user3@mail.com" $To = "email@mail.com" $smtpServer = "mail.server.com" $Node = gc env:comput...

Get disk space usage of database files

Sp_helpfile is an option to query the size of the database file but it does not give how much disk space out of the allocated is being used by the data or log file. Below is the query which can be used to fetch the details like disk space allocated to each data and log file for the database and how much is used and how much is free. It also gives the physical location of the files. USE DatabaseName; GO SELECT NAME AS LogicalFileName ,CAST(size / 128.0 AS DECIMAL(20, 2)) [Total(MB)] ,CAST(CAST(FILEPROPERTY(NAME, 'SpaceUsed') AS INT) / 128.0 AS DECIMAL(20, 2)) AS [Used(MB)] ,CAST((size - CAST(FILEPROPERTY(NAME, 'SpaceUsed') AS INT)) / 128.0 AS DECIMAL(20, 2)) [Remaining(MB)] ,physical_name AS Path FROM sys.database_files

Make Money from Surveys