Overview of the SMBShare Module for PowerShell 3


The SMBShare Module that comes with PowerShell 3 lets you administer network shares directly from within PowerShell. The cmdlets are easy to use, and it is my new favorite way to work with network shares.

It’s the Quickest Way to Create a Network Share with PowerShell

It’s very easy to create network shares with PowerShell by using the SMBShare module that comes in PowerShell version 3.

How to Install the SMBShare Module for PowerShell 3

If you’ve already got PowerShell v.3, then you’re already all set.  You don’t even have to add a pssnapin or import a module.  One of my favorite PowerShell 3 features is the ability to load modules on demand when one of the commands in the module is called.


So if you want to load the SMBShare module, just run one of the commands I’m getting ready to tell you about!

The SMBShare “Get-” Commands

The SMBShare module includes 11 different Get commands, for finding out the current state of affairs with your SMB shares and your SMB client configuration.

Get-SmbClientConfiguration:  This will tell you how a computer, either locally or remote through WMI connection, is configured.  It returns items such as how long to stay connected (KeepConn) and how soon to consider a dropped session a timeout (SessionTimeout).

Find Tech Jobs on Dice!

Get-SmbClientNetworkInterface: All of the Network Interfaces, including wired, wireless, and logical, are all displayed.  this makes:
[code language=”powershell”]
#Get all of the IP addresses for all network interfaces
$AllIPs  = Get-SMBClientNetworkInterfaces | Select-Object -ExpandProperty  IPAddresses
Get-SmbConnection:  This lists active SMB connections and even includes Bytes Sent and Received.  Administrative PowerShell session  required.

Hey, have you seen the cool trick I use to color my administrative shells with a red background?  It’s really easy.

Read: How to Change Background Color on Administrative PowerShell Session

Get-SmbMapping  gives you a list of mapped drives, and returns properties such as LocalDrive (the drive letter the mapped drive is assigned) and the RemotePath, which is the mapped network share.  It also displays the status.

Here’s hoping that I can finally and easily remove old sessions to servers to I can connect to an administrative share without getting the stupid “Cannot connect with more than one user name to a server” error.  BTW, in case you didn’t know about it, there’s a sneaky trick to get a second set of credentials mapped to a server share

Get-SmbMultichannelConnection  If you’re using SMB Multichannel, then this is your tool of choice for getting that connection information.  I’m not using it, so I’ll leave it open.  If you’ve got some information about this, please send a note in the comments and I’ll update with your facts and give you credit.

Get-SmbOpenFile I love this one!  Gets all of the files that are currently open.  This was available in the Server properties through the GUI, but this is an administrative function that was a hassle to script in WMI and it’s so much easier now.

Get-SmbServerConfiguration Similar to the first command we mentioned, but this is the server settings instead of the client settings

Get-SmbShare All shares, including administrative and hidden shares, are included with this simple command.    You can quickly see at a glance which of your shares are temporary, permanent, using shadow copy, and its status.  Another one that makes an admins job much easier.

Get-SmbShareAccess  You were probably already asking the question:  ”Does Get-SMBShare tell you who has access?”   But no, it doesn’t.  Instead, you use the Get-SMBShare command, then pipe it into Get-SMBShareAccess
[code language=”powershell”]
#Get a list of any users that write to any shares that are not online

$Shares = Get-SMBShare

$Offline = $Shares | Where-Object {$_.ShareState -eq “Offline”}

$Users = $Offline  | Get-SMBShareAccess | Where-Object {$_.AccessRight -le “Change”}
That’s just the Get Commands, but I think you can tell a lot from the Get commands, because that’s what’s going to feed into the Set commands.

Still, I bet you’d like to know which of the nouns you’ll be able to modify using the SMBShare module.

Set, New, and Remove – the rest of the SMBShare module cmdlets.

By the nouns, that is, the objects that you’re able to administer, here is what you can do to the different SMBShare objects.

SMBClientConfiguration: In addition to Get-, you can also use Set-SMBClientConfiguration.

SMBShare: You can also use New-SMBShare, Remove-SMBShare, and Set-SMBShare.

SMBMultichannelConnection: Update-SMBMultichannelConnection is the only additional cmdlet for working with the Multi-channel SMB connections.

SMBServerConfiguration: Like client configuration, you also get Set-SMBServerConfiguration.

SMBOpenFile: If you were excited to see the Get-SMBOpenFile, you were probably eagerly hoping that this command was included.  Yes, you also get Close-SMBOpenFile.

SMBShareAccess: Also available for administering share permissions is Block-SMBShareAccess, Grant-SMBShareAccess, Revoke-SMBShareAccess, and Unblock-SMShareAccess.

SMBMapping: New-SMBMapping and Remove-SMBMapping are also available, so you can now actually map real drives from within PowerShell, not just PSDrives that exist only in the PowerShell session.

SMBSession: When you’re ready to end a session, you can do it with style using the Close-SMBSession cmdlet.

In Ending

Well, it’s been a great journey, and this exercise was as good for me to learn as it was for you to learn.  While I had already been using some of the SMBShare commands, actually taking the time to try the different cmdlets and seeing which ones are available is really beneficial.

My favorite two that I’ll use the most:



What about you?  What’s your favorite from this module?  Let me know if you liked this article by connecting in the comments below, and please subscribe.

Find Tech Jobs on Dice!