How to use the new SMB 3.0 WMI classes in Windows Server 2012 and Windows 8 (from PowerShell)

If you're an IT Administrator, you're likely to use the new SMB PowerShell cmdlets to manage your SMB 3.0 file shares. You can find details about those at https://blogs.technet.com/b/josebda/archive/2012/06/27/the-basics-of-smb-powershell-a-feature-of-windows-server-2012-and-smb-3-0.aspx

However, if you're a developer, you might be interested in learning about the WMI v2 classes that are behind those PowerShell cmdlets. They are easy to use and exactly match the PowerShell functionality. In fact, you can test them via PowerShell using the Get-WMIObject cmdlet. These WMIv2 classes are available for both Windows 8 and Windows Server 2012.

What is sometimes a little harder to figure out is exactly how to find detailed information about them if you don't know exactly where to look. The key information you need is the namespace for those classes. In the case of SMB, the namespace is RootMicrosoftWindowsSMB. Here is a sample PowerShell cmdlet to query the WMI information:

PS C:Windowssystem32> Get-WMIObject -Namespace "rootMicrosoftWindowsSMB" -List "MSFT_*"

   NameSpace: ROOTMicrosoftWindowsSMB

Name Methods Properties
---- ------- ----------
MSFT_SmbShare {CreateShare, Gra... {AvailabilityType, CachingMode, ...
MSFT_SmbShareAccessControlEntry {} {AccessControlType, AccessRight,...
MSFT_WmiError {} {CIMStatusCode, CIMStatusCodeDes...
MSFT_ExtendedStatus {} {CIMStatusCode, CIMStatusCodeDes...
MSFT_SmbClientNetworkInterface {} {FriendlyName, InterfaceIndex, I...
MSFT_SmbServerNetworkInterface {} {FriendlyName, InterfaceIndex, I...
MSFT_SmbConnection {} {ContinuouslyAvailable, Credenti...
MSFT_SmbOpenFile {ForceClose} {ClientComputerName, ClientUserN...
MSFT_SmbMultichannelConnection {Refresh} {ClientInterfaceFriendlyName, Cl...
MSFT_SmbClientConfiguration {GetConfiguration... {ConnectionCountPerRssNetworkInt...
MSFT_SmbShareChangeEvent {} {EventType, Share}
MSFT_SmbServerConfiguration {GetConfiguration... {AnnounceComment, AnnounceServer...
MSFT_SmbSession {ForceClose} {ClientComputerName, ClientUserN...
MSFT_SmbMapping {Remove, Create} {LocalPath, RemotePath, Status}
MSFT_SmbMultichannelConstraint {CreateConstraint} {InterfaceAlias, InterfaceGuid, ...

To test one of these via PowerShell, you can use the same Get-WMIObject cmdlet. Here's a sample (with the traditional PowerShell and the WMI equivalent):

PS C:Windowssystem32> Get-SmbShare | Select Name, Path

Name Path
---- ----
ADMIN$ C:Windows
C$ C:
IPC$
Users C:Users

 

PS C:Windowssystem32> Get-WMIObject -Namespace "rootMicrosoftWindowsSMB" MSFT_SmbShare | Select Name, Path

Name Path
---- ----
ADMIN$ C:Windows
C$ C:
IPC$
Users C:Users

Obviously the two outputs are exactly the same and the PowerShell version is much simpler. You'll only use WMI if you're really running this from an application, where using WMI classes might be simpler than invoking PowerShell.

The WMI side could get even more complex if you have to filter things or invoke a method of the WMI class (instead of simply getting properties of the returned object).

For instance, here's how you would use WMI to invoke the GetConfiguration method of the MSFT_SmbClientConfiguration class, which would be the equivalent of using the Get-SmbClientConfiguration PowerShell cmdlet:

PS C:Windowssystem32> Get-SmbClientConfiguration

ConnectionCountPerRssNetworkInterface : 4
DirectoryCacheEntriesMax : 16
DirectoryCacheEntrySizeMax : 65536
DirectoryCacheLifetime : 10
EnableBandwidthThrottling : True
EnableByteRangeLockingOnReadOnlyFiles : True
EnableLargeMtu : True
EnableMultiChannel : True
DormantFileLimit : 1023
EnableSecuritySignature : True
ExtendedSessionTimeout : 1000
FileInfoCacheEntriesMax : 64
FileInfoCacheLifetime : 10
FileNotFoundCacheEntriesMax : 128
FileNotFoundCacheLifetime : 5
KeepConn : 600
MaxCmds : 50
MaximumConnectionCountPerServer : 32
OplocksDisabled : False
RequireSecuritySignature : False
SessionTimeout : 60
UseOpportunisticLocking : True
WindowSizeThreshold : 8 

PS C:Windowssystem32> $cc = Invoke-WMIMethod -Namespace "rootMicrosoftWindowsSMB" -Class MSFT_SmbClientConfiguration -Name GetConfiguration
PS C:Windowssystem32> $cc

__GENUS : 1
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH : __PARAMETERS
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER : <REMOVED>
__NAMESPACE : ROOTMicrosoftWindowsSmb
__PATH : \<REMOVED>ROOTMicrosoftWindowsSmb:__PARAMETERS
Output : System.Management.ManagementBaseObject
ReturnValue : 0
PSComputerName : <REMOVED>

PS C:Windowssystem32> $cc.Output

__GENUS : 2
__CLASS : MSFT_SmbClientConfiguration
__SUPERCLASS :
__DYNASTY : MSFT_SmbClientConfiguration
__RELPATH :
__PROPERTY_COUNT : 23
__DERIVATION : {}
__SERVER : <REMOVED>
__NAMESPACE : ROOTMicrosoftWindowsSMB
__PATH :
ConnectionCountPerRssNetworkInterface : 4
DirectoryCacheEntriesMax : 16
DirectoryCacheEntrySizeMax : 65536
DirectoryCacheLifetime : 10
DormantFileLimit : 1023
EnableBandwidthThrottling : True
EnableByteRangeLockingOnReadOnlyFiles : True
EnableLargeMtu : True
EnableMultiChannel : True
EnableSecuritySignature : True
ExtendedSessionTimeout : 1000
FileInfoCacheEntriesMax : 64
FileInfoCacheLifetime : 10
FileNotFoundCacheEntriesMax : 128
FileNotFoundCacheLifetime : 5
KeepConn : 600
MaxCmds : 50
MaximumConnectionCountPerServer : 32
OplocksDisabled : False
RequireSecuritySignature : False
SessionTimeout : 60
UseOpportunisticLocking : True
WindowSizeThreshold : 8
PSComputerName : <REMOVED>

You can find more information about these SMB WMI classes at https://msdn.microsoft.com/en-us/library/windows/desktop/hh830479.aspx