PowerShell SmbShare module (2/3)
Part 2 of the SmbShare module: New-Smb* cmdlets create shares, drive mappings, QUIC ports and certificate mappings; Remove-Smb* deletes them; Reset-Smb*Configuration puts client or server settings back to the Windows default. All of them change live file servers, so they need admin and care.
225.1 What it does, where it runs
- Built into Windows 10/11 and Windows Server; PowerShell 5.1 and 7.
- New, Remove and Reset need an admin PowerShell and directly change shares, mappings or server settings.
- Get-Command for the verbs New and Remove counts 16 cmdlets (New-SmbGlobalMapping was in part 1).
- New-SmbShare: -Name and -Path are required, alias nsmbs.
- On the office PC only Get-Command and Get-Help ran (not even -WhatIf); examples are from Microsoft Learn and a Samba lab.
PowerShell
Get-Command -Module SmbShare ` -Verb New,Remove | Measure-ObjectGet-Help New-SmbShareOutput
$ Get-Command -Module SmbShare -Verb New,Remove | Measure-ObjectCount : 16$ Get-Help New-SmbShareNAME New-SmbShareSYNTAX New-SmbShare [-Name] <string> [-Path] <string> [[-ScopeName] <string>] [[-QoSFlowScope] {File | Share | User | Session}] [[-QoSPolicyId] <string>] [-Temporary] [-ContinuouslyAvailable <bool>] ALIASES nsmbsREMARKS Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.225.2 How it works: create, map, remove
- Step 1
1.File server 192.168.245.10: New-SmbShare creates share reports
- Step 2
2.Client 192.168.245.20: New-SmbMapping, SMB on TCP 445 via the switch
- Step 3
3.Connected: reports
- Step 4
4.Server also listens on alternative port 4455: same share OK
- Step 5
5.Admin runs Remove-SmbShare
- Step 6
6.Next request on 445 rejected: BAD_NETWORK_NAME
225.3 New-SmbShare (21)
- Turns a server folder into an SMB share for remote clients.
- -EncryptData $True makes it an encrypted share.
- Access: -FullAccess, -ChangeAccess, -ReadAccess, -NoAccess (or -SecurityDescriptor).
- Other options: -FolderEnumerationMode AccessBased, -CachingMode, -ContinuouslyAvailable, -ConcurrentUserLimit; a -Temporary share does not survive a restart.
- Docs note: The WhatIf parameter does not work with this cmdlet.
PowerShell
New-SmbShare -Name "Data" -Path "J:\Data" ` -EncryptData $True$Parameters = @{ Name = 'VMSFiles' Path = 'C:\ClusterStorage\Volume1\VMFiles' ChangeAccess = 'CONTOSO\Finance Users', 'CONTOSO\HR Users' FullAccess = 'Administrators'}New-SmbShare @Parameters225.4 New-SmbMapping (20)
- Client side: maps a drive letter to a remote share.
- Credentials: -UserName/-Password or -Credential; -SaveCredentials; -Persistent $true survives a restart.
- -RequireIntegrity = signing mandatory, -RequirePrivacy = encryption mandatory, -BlockNTLM.
- -TransportType None|TCP|QUIC; -TcpPort/-QuicPort/-RdmaPort tell the client the server's alternative port.
PowerShell
New-SmbMapping -LocalPath "X:" ` -RemotePath "\\Contoso-SO\VMFiles"Output
Status Local Path Remote Path------ ---------- -----------OK X: \\Contoso-SO\VMFiles225.5 SMB over QUIC and multichannel
- New-SmbServerAlternativePort (5): adds an alternative port; -TransportType accepts only QUIC.
- New-SmbServerCertificateMapping (11): maps a certificate (My store, thumbprint) to a server name; -RequireClientAuthentication makes the server validate client certificates.
- New-SmbMultichannelConstraint (6): client uses only the listed interfaces for a server; applies only to the Default SMB instance.
- Remove-SmbMultichannelConstraint (8) -Force removes it without confirmation.
PowerShell
New-SmbServerAlternativePort ` -TransportType QUIC -Port 1$params = @{ Name = "fs2.contoso.com" Thumbprint = "88032B3551FAF7DE26EFFFF814AA086E3DBD2A4F" StoreName = "My" Subject = "CN=2022-ae-02"}New-SmbServerCertificateMapping @paramsNew-SmbMultichannelConstraint ` -ServerName "Contoso-SO" ` -InterfaceAlias "RDMA1", "RDMA2"Remove-SmbMultichannelConstraint ` -ServerName "Contoso-SO" ` -InterfaceIndex 12 -ForceOutput
InterfaceAlias : RDMA1InterfaceIndex : 12ServerName : Contoso-SOInterfaceAlias : RDMA2InterfaceIndex : 15225.6 Remove- cmdlets
| Cmdlet | Options | Notes |
|---|---|---|
| Remove-SmbShare | 8 | Confirm prompt; -ScopeName for cluster shares; existing connections forcibly disconnected |
| Remove-SmbMapping | 9 | -UpdateProfile so it does not come back after restart |
| Remove-SmbGlobalMapping | 6 | Same for a global mapping |
| Remove-SmbServerAlternativePort | 7 | Removes the QUIC port added by New |
| Remove-SmbServerCertificateMapping | 14 | By name + thumbprint; confirm first |
| Remove-SmbClientCertificateMapping | 14 | -StoreName My -Force removes ALL mappings of the store; use -Thumbprint/-Namespace for one |
| Remove-SmbBandwidthLimit | 5 | No parameter = all categories; -Category LiveMigration = one |
| Remove-SmbComponent | 2 | Removes SMB1 components (SMB1Protocol, -Client, -Server, -Deprecation) |
PowerShell
Remove-SmbShare -Name "Data"Remove-SmbShare -Name "VMFiles" ` -ScopeName "Contoso-SO" -ForceRemove-SmbMapping -LocalPath "Y:"Remove-SmbGlobalMapping -LocalPath "G:"Remove-SmbServerAlternativePort ` -TransportType QUIC -Port 1Remove-SmbClientCertificateMapping ` -StoreName "My" -ForceRemove-SmbBandwidthLimit ` -Category LiveMigrationRemove-SmbComponent -Name SMB1ProtocolOutput
Performing operation `Remove-Share` on Target 'Contoso-FS,Data'.225.7 Reset-SmbClientConfiguration (41) + Reset-SmbServerConfiguration (52)
- Every parameter is a switch that resets its own setting to the Windows default; -All resets everything.
- Client switches: -RequireEncryption, -BlockNTLM, -Smb2DialectMin/Max, -EnableMultiChannel, -EnableLargeMtu, -EnableSMBQUIC, cache timeouts, -EnableLoadBalanceScaleOut.
- Server switches: -EncryptData, -RejectUnencryptedAccess, -EnableSMB2Protocol, -AutoShareServer, leasing/oplocks, Max* limits, -EnableStrictNameChecking, SMB1-only -MaxMpxCount/-MaxWorkItems.
- Reset = Windows default, NOT your company's security baseline; never run it on a managed server without permission.
PowerShell
Reset-SmbClientConfiguration ` -EnableLargeMtu -Confirm:$falseReset-SmbServerConfiguration ` -RejectUnencryptedAccess -Confirm:$false225.8 Linux equivalent: Samba net conf lab
- Lab: Samba server 192.168.245.10 (alpine), client container, throwaway lab user asha.
- net conf addshare = New-SmbShare; smbclient connect = New-SmbMapping (no drive letters on Linux).
- smb ports = 445 4455 gives an alternative port; removing 4455 = Remove-SmbServerAlternativePort.
- net conf delshare = Remove-SmbShare; the folder and files on disk stay safe.
Terminal
net conf addshare reports /srv/reports \ writeable=y guest_ok=N 'Q3 reports'net conf setparm reports 'valid users' ashasmbclient -L //192.168.245.10 \ -U asha%LabPass225smbclient //192.168.245.10/reports \ -U asha%LabPass225 \ -c 'put /tmp/hello.txt hello.txt; ls'smbclient -p 4455 \ //192.168.245.10/reports \ -U asha%LabPass225 -c lsnet conf delshare reportsOutput
$ smbclient -L //192.168.245.10 -U asha%LabPass225 Sharename Type Comment --------- ---- ------- IPC$ IPC IPC Service (N225 lab file server) reports Disk Q3 reports[srv] $ netstat -ltn | grep -E ':(445|4455) 'tcp 0 0 192.168.245.10:445 0.0.0.0:* LISTEN tcp 0 0 192.168.245.10:4455 0.0.0.0:* LISTEN [client] $ smbclient -p 4455 //192.168.245.10/reports -U asha%LabPass225 -c ls q3.txt N 18 Mon Nov 9 14:36:55 2026 hello.txt A 12 Mon Nov 9 14:37:04 2026 (after smb ports = 445 and smbd restart)[client] $ smbclient -p 4455 //192.168.245.10/reports -U asha%LabPass225 -c lsdo_connect: Connection to 192.168.245.10 failed (Error NT_STATUS_CONNECTION_REFUSED)(after net conf delshare reports)[client] $ smbclient //192.168.245.10/reports -U asha%LabPass225 -c lstree connect failed: NT_STATUS_BAD_NETWORK_NAME[srv] $ ls -l /srv/reports-rwxr--r-- 1 asha asha 12 Nov 9 14:37 hello.txt-rw-r--r-- 1 asha asha 18 Nov 9 14:36 q3.txt225.9 Common mistakes
- Running Remove-SmbShare while users work on it: connections are forcibly disconnected and cached data can be lost; check Get-SmbSession first.
- Trusting -WhatIf on New-SmbShare: the docs say it does not work with this cmdlet, so the share may really be created.
- Remove-SmbClientCertificateMapping -StoreName My -Force when you meant one mapping: it removes all of them.
- Thinking Reset restores your hardened config; it restores the Windows default.
225.10 Interview tips
- Encrypted share with change access for HR: New-SmbShare -Name -Path -EncryptData $true -ChangeAccess 'HR group' -FullAccess 'Admins' in an admin shell.
- Effective access = the more restrictive of share and NTFS permissions; check both.
- New-SmbShare creates on the server, New-SmbMapping maps on the client; alternative port + certificate mapping are for SMB over QUIC.
- Before Remove-SmbShare check Get-SmbSession; Reset = Windows default.
- Samba: net conf addshare / delshare, smbclient -p for an alternative port.