Create an SMB share.
Syntax New-SmbShare [-Name] String [-Path] String [-ContinuouslyAvailable Boolean] [-Description String] [-ConcurrentUserLimit UInt32] [-CATimeout UInt32] [-FolderEnumerationMode FolderEnumerationMode] [-CachingMode CachingMode] [-FullAccess String[]] [-ChangeAccess String[]] [-ReadAccess String[]] [-NoAccess String[]] [-SecurityDescriptor String] [-Temporary] [[-ScopeName] String] [-EncryptData Boolean] [-CompressData Boolean] [-LeasingMode LeasingMode] [-CimSession CimSession[]] [-ThrottleLimit Int32] [-AsJob] [-WhatIf] [-Confirm] [CommonParameters] Key -AsJob Run the cmdlet as a background job. Use this parameter to run commands that take a long time to complete. -CachingMode Specify the caching mode of the offline files for the SMB share. There are five caching modes: None Prevent users from storing documents and programs offline. Manual Allow users to identify the documents and programs that they want to store offline. Programs Automatically store documents and programs offline. Documents Automatically store documents offline. BranchCache Enable BranchCache and manual caching of documents on the shared folder. -CATimeout The continuous availability time-out of the SMB share. -ChangeAccess Which users are granted modify permission to access the share. Multiple users can be specified by using a comma-separated list. Each entry in the comma-separated list must be contained within single or double quotes, for example 'CONTOSO\Finance Users','CONTOSO\HR Users'. -CimSession Run the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of New-CimSession or Get-CimSession. The default is the current session on the local computer. -CompressData Indicates that SMB compression is requested for all client connections that support it. -ConcurrentUserLimit The maximum number of concurrently connected users that the new SMB share may accommodate. If this parameter is set to zero (0), then the number of users is unlimited. By default, new SMB shares have no limit on the number of concurrent connections. -Confirm Prompt for confirmation before running the cmdlet. -ContinuouslyAvailable Indicate that the shares is continuously available. (SMB Transparent Failover setup in Windows Failover Clustering configuration). -Description An optional description of the SMB share. A description of the share can be displayed by running Get-SmbShare. Specify an empty string to clear the current description. Max length = 256 characters. -EncryptData Indicate that the share is encrypted. -FolderEnumerationMode Which files and folders in the new SMB share will be visible to the users. Accepted values: AccessBased SMB does not the display the files and folders for a share to a user unless that user has rights to access the files and folders. By default, access-based enumeration is disabled for new SMB shares. Unrestricted Display files and folders to a user even if the user does not have access permission to them. -FullAccess Which accounts are granted full permission to access the share. Use a comma-separated list to specify multiple accounts. Each entry in the comma-separated list must be contained within single or double quotes, for example 'CONTOSO\Finance Users','CONTOSO\HR Users'. An account may not be specified more than once in the FullAccess, ChangeAccess, or ReadAccess parameter lists, but may be specified once in the FullAccess, ChangeAccess, or ReadAccess parameter list and once in the NoAccess parameter list. -LeasingMode Specifies SMB leasing and oplock behaviors for application compatibility. Accepted values: Full Use default lease and oplock behaviors from SMB3. Shared Grant read-caching lease but not write or handle-caching. None No oplocks or leases, behave like SMB1 (not recommended). -Name The name for the SMB share. The names pipe and mailslot are reserved for use by the computer. Share names can be up to a maximum of 80 characters long. The SMB share name can use any character allowed by Windows for files and directories. -NoAccess Which accounts are denied access to the SMB share. Multiple accounts can be specified by supplying a comma-separated list. Each entry in the comma-separated list must be contained within single or double quotes, for example 'CONTOSO\Finance Users','CONTOSO\HR Users'. -Path The path of the location of the folder to share. The path must be fully qualified. Relative paths or paths that contain wildcard characters aren't permitted. -ScopeName The scope name of the share. -SecurityDescriptor The security descriptor for the SMB share in string format. -Temporary Specifies the new SMB share is temporary and will not persist beyond the next restart of the computer. By default, new SMB shares aren't temporary. -ThrottleLimit Specifies the maximum number of concurrent operations that can be established to run the cmdlet. If this parameter is omitted or a value of 0 is entered, then PowerShell calculates an optimum throttle limit for the cmdlet based on the number of CIM cmdlets that are running on the computer. The throttle limit applies only to the current cmdlet, not to the session or to the computer. -WhatIf Shows what would happen if the cmdlet runs. The cmdlet is not run.
The New-SmbShare cmdlet exposes a file system folder to remote clients as a Server Message Block (SMB) share. To delete a share that was created by this cmdlet, use the Remove-SmbShare cmdlet.
This cmdlet returns a MSFT_SmbShare object that represents the modified share.
Create an SMB share:
PS C:\> $Parameters = @{ Name = 'VMSFiles' Path = 'C:\ClusterStorage\Volume1\VMFiles' FullAccess = 'Contoso\Administrator', 'Contoso\Contoso-HV1$' } PS C:\> New-SmbShare @Parameters
Create an encrypted SMB share:
PS C:\> New-SmbShare -Name "Data" -Path "J:\Data" -EncryptData $True
Create an SMB share with Multiple Permissions:
PS C:\> $Parameters = @{
Name = 'VMSFiles'
Path = 'C:\ClusterStorage\Volume1\VMFiles'
ChangeAccess = 'CONTOSO\Finance Users','CONTOSO\HR Users'
FullAccess = 'Administrators'
}
PS C:\> New-SmbShare @Parameters
"The miracle is this: the more we share the more we have" ~Leonard Nimoy
Get-SmbShare - Retrieve the SMB shares on the computer.
Set-SmbShare - Modify the properties of an SMB share.
Get-SmbShareAccess - Retrieve the ACL of an SMB share.
ShareAudit.vbs - Audit shares across the domain (Redmond Mag).
Grant-SmbShareAccess - Add an allow ACE for a trustee to the security descriptor of the SMB share.
Get-CIMinstance win32_share