A while back, I showed how to use PowerShell V2 and our old SMB WMIv1 object to explain how to find the free space behind a file share (essentially the free space for the volume that contains the file share). That post is available at http://blogs.technet.com/b/josebda/archive/2010/04/08/using-powershell-v2-to-gather-info-on-free-space-on-the-volumes-of-your-remote-file-server.aspx. While that post was a good example of how to construct a more elaborate solution using PowerShell, it was a little complicated :-).
Now, with Windows Server 2012, PowerShell V3 and SMB PowerShell, things got much simpler. I can essentially do the same thing with a simple one-liner.
For instance, to see the free space on the volume behind a specific share named TEST, you can use
Get-Volume -Id (Get-SmbShare TEST).Volume
To list the volumes for all shares on a specific server, you can use:
Get-SmbShare | ? Volume -ne $null | % { $_ | FL ; Get-Volume -Id $_.Volume | FL }
Note that you can also execute those remotely, pointing to the server where the shares are located:
Get-Volume -CimSession Server1 -Id (Get-SmbShare TEST -CimSession Server1).Volume
Get-SmbShare -CimSession Server1 | ? Volume -ne $null | % { $_ | FL ; Get-Volume -CimSession Server1 -Id $_.Volume | FL }
Here is a complete example, with output. First a simple query to find the information for a volume behind a share
PS C:\> Get-Volume -Id (Get-SmbShare VMS1).Volume
DriveLetter FileSystemLabel FileSystem DriveType HealthStatus SizeRemaining Size
----------- --------------- ---------- --------- ------------ ------------- ----
I NTFS Fixed Healthy 78.85 GB 100 GBPS C:\> Get-Volume -Id (Get-SmbShare Projects).Volume | Select *
HealthStatus : Healthy
DriveType : Fixed
DriveLetter :
FileSystem : CSVFS
FileSystemLabel :
ObjectId : \\?\Volume{20795fea-b7da-43dd-81d7-4d346c337a73}\
Path : \\?\Volume{20795fea-b7da-43dd-81d7-4d346c337a73}\
Size : 107372081152
SizeRemaining : 85759995904
PSComputerName :
CimClass : ROOT/Microsoft/Windows/Storage:MSFT_Volume
CimInstanceProperties : {DriveLetter, DriveType, FileSystem, FileSystemLabel...}
CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties
Now a more complete query, showing all shares starting with VMS and information on the volume behind them:
PS C:\> Get-SmbShare VMS* | ? Volume -ne $null | % { $_ | FL ; Get-Volume -Id $_.Volume | FL }
Name : VMS1
ScopeName : FST2-FS
Path : I:\VMS
Description :DriveLetter : I
DriveType : Fixed
FileSystem : NTFS
FileSystemLabel :
HealthStatus : Healthy
ObjectId : \\?\Volume{b02c4ba7-e6f1-11e1-93eb-0008a1c0ef0d}\
Path : \\?\Volume{b02c4ba7-e6f1-11e1-93eb-0008a1c0ef0d}\
Size : 107372081152
SizeRemaining : 84665225216
PSComputerName :Name : VMS2
ScopeName : FST2-FS
Path : J:\VMS
Description :DriveLetter : J
DriveType : Fixed
FileSystem : NTFS
FileSystemLabel :
HealthStatus : Healthy
ObjectId : \\?\Volume{b02c4bb1-e6f1-11e1-93eb-0008a1c0ef0d}\
Path : \\?\Volume{b02c4bb1-e6f1-11e1-93eb-0008a1c0ef0d}\
Size : 107372081152
SizeRemaining : 84665225216
PSComputerName :Name : VMS3
ScopeName : FST2-SO
Path : C:\ClusterStorage\Volume1\VMS
Description :DriveLetter :
DriveType : Fixed
FileSystem : CSVFS
FileSystemLabel :
HealthStatus : Healthy
ObjectId : \\?\Volume{20795fea-b7da-43dd-81d7-4d346c337a73}\
Path : \\?\Volume{20795fea-b7da-43dd-81d7-4d346c337a73}\
Size : 107372081152
SizeRemaining : 85759995904
PSComputerName :Name : VMS4
ScopeName : FST2-SO
Path : C:\ClusterStorage\Volume2\VMS
Description :DriveLetter :
DriveType : Fixed
FileSystem : CSVFS
FileSystemLabel :
HealthStatus : Healthy
ObjectId : \\?\Volume{fb69e20a-5d6a-4dc6-a0e9-750291644165}\
Path : \\?\Volume{fb69e20a-5d6a-4dc6-a0e9-750291644165}\
Size : 107372081152
SizeRemaining : 84665225216
PSComputerName :Name : VMS5
ScopeName : *
Path : D:\VMS
Description :DriveLetter : D
DriveType : Fixed
FileSystem : NTFS
FileSystemLabel : LocalFS1
HealthStatus : Healthy
ObjectId : \\?\Volume{58a38e4e-e2fd-11e1-93e8-806e6f6e6963}\
Path : \\?\Volume{58a38e4e-e2fd-11e1-93e8-806e6f6e6963}\
Size : 181336535040
SizeRemaining : 136311140352
PSComputerName :
Finally, not for the faint of heart, a more complex query from a remote file server which creates a custom result combining share information and volume information:
PS C:\> Get-SmbShare -CimSession FST2-FS2 | ? Volume -ne $null | % { $R = "" | Select Share, Path, Size, Free; $R.Share=$_.Name; $R.Path=$_.Path; Get-Volume -CimSession FST2-FS2 -Id $_.Volume | % { $R.Size=$_.Size; $R.Free=$_.SizeRemaining; $R | FL }}
Share : ADMIN$
Path : C:\Windows
Size : 68352471040
Free : 44692242432Share : C$
Path : C:\
Size : 68352471040
Free : 44692242432Share : ClusterStorage$
Path : C:\ClusterStorage
Size : 68352471040
Free : 44692242432Share : D$
Path : D:\
Size : 181336535040
Free : 177907777536Share : Projects
Path : C:\ClusterStorage\Volume1\SHARES\PROJECTS
Size : 107372081152
Free : 85759995904Share : VMFiles
Path : C:\ClusterStorage\Volume1\VMFiles
Size : 107372081152
Free : 85759995904Share : VMS3
Path : C:\ClusterStorage\Volume1\VMS
Size : 107372081152
Free : 85759995904Share : VMS4
Path : C:\ClusterStorage\Volume2\VMS
Size : 107372081152
Free : 84665225216Share : Witness
Path : C:\ClusterStorage\Volume1\Witness
Size : 107372081152
Free : 85759995904