Powershell 3.0

Submitted by: Submitted by

Views: 10

Words: 1104

Pages: 5

Category: Science and Technology

Date Submitted: 10/04/2015 11:33 AM

Report This Essay

Managing File Shares with Windows PowerShell

How to use new SMBShare and SMBWitness modules to work with file shares

SMB

Server Message Block (SMB) is a protocol that's used extensively by Windows for sharing files, printers, serial ports, and communications abstractions such as named pipes and mail slots between computers. Windows 8 and Windows Server 2012 introduced the SMBShare and SMBWitness modules to manage SMB file servers and SMB file shares. Thanks to the module auto-loading feature in Windows PowerShell 3.0 and later, these modules are automatically loaded whenever you refer to any of the contained cmdlets.

Although not strictly required thanks to module auto-loading, you can import the SMBShare and SMBWitness modules in PowerShell using the Import-Module cmdlet:

Import-Module SmbShare

Import-Module SmbWitness

An even easier command to import the modules is:

Import-Module Smb*

With that done, let's perform the same tasks as performed using WMI.

Using the Modules to Enumerate Shares

Generating a list of your local shares couldn't be easier. You just need to call the Get-SmbShare cmdlet without any parameters:

Get-SmbShare

If you want to list the shares on a remote machine, you just add the -Name parameter:

Get-SmbShare -Name LH24CU142

Using the Modules to Create a Local Share

Creating a share is handled by the New-SmbShare cmdlet. To use it, you need to supply, at a minimum, the share's name and path:

New-SmbShare -Name Spring -Path C:\Spring

With said that, it doesn't hurt to include some additional details, such as a description and some access rights. The following command assigns full access to Administrators and read-only access to everyone else:

New-SmbShare -Name Spring -Path C:\Spring `

-Description 'Shared Folder for Spring Students' `

-FullAccess Administrator -ReadAccess Everyone

Note that the New-SmbShare command won't create the folder if it doesn't exist.

Using the Modules to Create a Remote...