Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Find storage including mount points sql/powershell


Find storage including mount points sql/powershell

Author
Message
genehunter29009
genehunter29009
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 Visits: 212
Comments posted to this topic are about the item Find storage including mount points sql/powershell
dineshMVP
dineshMVP
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 145
It was really helpful, Gene. Thanks
mhickin 11975
mhickin 11975
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 327
Actually, if you just want to see the volumes/mount points that are currently in use by this sql instance, you don't need powershell.
I use this query across all my sql instances using powershell to collect and centralise the data. Is very useful for capacity planning.

;WITH FileIds
AS
( SELECT DISTINCT database_id, file_id
FROM MASTER.SYS.master_files AS mf
)

SELECT DISTINCT
volume_mount_point ,
logical_volume_name,
(total_bytes / 1073741824) SizeGB ,
(available_bytes / 1073741824) FreeSpaceGB,
(available_bytes / 1073741824.0)/ (total_bytes / 1073741824.0)*100 PercentFree
FROM FileIds f
CROSS APPLY sys.dm_os_volume_stats (f.database_id, f.file_id)
mops33
mops33
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 169
The powershell script below will return information on drives and mountpoints regardless of whether they host database files.
It has some minor deficiencies but works OK.
Has a critical threshold [%], below which items are highlighted with a red background.
Set the value of variable $server

param(
[int]$MountPointsOnly = $false,
[int]$CriticalThreshold = 15
)

$ErrorActionPreference = "Stop"

Clear-Host
$server = 'ThisServer'

$serverExists = ping "$server" -ne 1
if($serverExists -like "*Ping request could not find host*"){
Write-host "***`n`tCould not connect to server: $server`n***" #-BackgroundColor White -ForegroundColor Red
}else{
try{
if($MountPointsOnly){
$v = gwmi -class "win32_volume" -namespace "root/cimv2" -ComputerName $server | Where-Object {$_.capacity -ne $null -and $_.DriveLetter -eq $null}
}else{
$v = gwmi -class "win32_volume" -namespace "root/cimv2" -ComputerName $server | Where-Object {$_.capacity -ne $null}
}
$OddLine = $true
$PadChar = '.'

if($v -eq $null){
Write-Host "No Mountpoints present on server: $server" `
}else{
Write-Host "Storage Space Report [in GB] - $server"
Write-Host "Drive Label".padright(40," ") -BackgroundColor DarkBlue `
"Free".padleft(5," ") `
"Total".padleft(7," ") `
"% Free ".padleft(12," ") `
-ForegroundColor White
foreach($d in $v | sort -Property caption){
if($OddLine){
$PadChar = ' '
$background = "Gray"
$OddLine = $false

} else {
$PadChar = ' '
$background = "White"
$OddLine = $true
}
if(($d.freespace /$d.Capacity*100) -lt $CriticalThreshold){
write-host (($d.DriveLetter + "").padright(4," ") + " " + $d.label).padright(40,$PadChar) ("{0:#,##0}" -f ($d.freespace/ 1GB)).padleft(5," ") " " `
("{0:#,##0}" -f ($d.capacity/ 1GB)).padleft(5," ") " " `
('{0Tongue2}' -f ($d.freespace /$d.Capacity)).padleft(10," ") -BackgroundColor Red -ForegroundColor Black
}else{
write-host (($d.DriveLetter + "").padright(4," ") + " " + $d.label).padright(40,$PadChar) ("{0:#,##0}" -f ($d.freespace/ 1GB)).padleft(5," ") " " `
("{0:#,##0}" -f ($d.capacity/ 1GB)).padleft(5," ") " " `
('{0Tongue2}' -f ($d.freespace /$d.Capacity)).padleft(10," ") -BackgroundColor $background -ForegroundColor Black
}
}
}
}catch{
Write-host "*** Could not connect to server: $server ***" -BackgroundColor White -ForegroundColor Red
}
}






Iwas Bornready
Iwas Bornready
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10144 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search