SkillPilotAI

PowerShell SmbShare module (1/3)

The SmbShare module is the PowerShell interface for SMB: shares, sessions, open files, mappings and SMB over QUIC. Part 1 covers the Block, Close, Get and Grant cmdlets, including the classic support question: who has this file locked?

224.1 What it does, where it runs

  • Built into Windows 10/11 and Windows Server; Windows PowerShell 5.1 and PowerShell 7.
  • The module has 59 cmdlets (Get-Command -Module SmbShare | Measure-Object).
  • Block, Close, Enable, Disable, Grant and New change state and need admin rights.
  • Even Get cmdlets reveal server and user names, so on the office PC only the count and Get-Help ran; outputs below are from the Microsoft Learn docs and a Samba lab.
PowerShell
Get-Command -Module SmbShare | Measure-ObjectGet-Help Get-SmbShare
Output
$ Get-Command -Module SmbShare | Measure-ObjectCount    : 59$ Get-Help Get-SmbShareNAME    Get-SmbShareSYNTAX    Get-SmbShare [[-Name] <string[]>] [[-ScopeName] <string[]>] [-Scoped <bool[]>] [-Special <bool[]>]    [-ContinuouslyAvailable <bool[]>] [-ShareState {Pending | Online | Offline}] [-FolderEnumerationMode {AccessBased    <bool[]>] [-IsolatedTransport <bool[]>] [-QoSFlowScope {File | Share | User | Session}] [-QoSPolicyId <string[]>]REMARKS    Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.

224.2 How it works: client side vs server side

SMB client and server views
  1. 1.asha 192.168.244.21 opens report.txt on \\filesrv\docs

  2. 2.Request reaches filesrv 192.168.244.10 on TCP 445

  3. 3.Client side: Get-SmbConnection shows filesrv\docs

  4. 4.ravi 192.168.244.22 connects to the public share

  5. 5.Server side: Get-SmbSession shows asha (1 open) and ravi (0)

  6. 6.Get-SmbOpenFile: report.txt is open by asha

Close vs Block
  1. 1.Close-SmbOpenFile: report.txt closed

  2. 2.Close-SmbSession: whole session ended

  3. 3.Client reconnects immediately

  4. 4.Block-SmbShareAccess adds Deny: ravi on docs

  5. 5.ravi's tree connect to docs

  6. 6.NT_STATUS_ACCESS_DENIED

Close only ends the current connection; only a block actually stops someone.

224.3 Common parameters

ParameterMeaning
-CimSessionRun on a remote computer (e.g. Server01)
-AsJobRun as a background job
-ThrottleLimitMax concurrent operations
-WhatIfOnly shows what would happen
-ConfirmAsk before running (Block/Close hit live users)
-Verbose, -ErrorAction ...Normal PowerShell common parameters

224.4 Block and Grant

  • Block-SmbClientAccessToServer (7, SMB over QUIC): terminates all connections of that client and blocks new ones; client identified by certificate -IdentifierType SHA256 or ISSUER.
  • Grant-SmbClientAccessToServer (7): allows a client and also adds a firewall rule; Get-SmbClientAccessToServer (3) lists allowed/blocked clients.
  • Block-SmbShareAccess (8): adds a Deny ACE on the share for -AccountName.
  • Grant-SmbShareAccess (9): adds an Allow entry with -AccessRight Full, Change or Read.
  • Effective access = the more restrictive of share and NTFS permissions.
PowerShell
$params = @{    Name = "Server01"    IdentifierType = "ISSUER"    Identifier = "CN=MyCertificateIssuer"    Force = $true}Block-SmbClientAccessToServer @paramsGrant-SmbClientAccessToServer @paramsBlock-SmbShareAccess -Name VMFiles `  -AccountName Contoso\GuestGrant-SmbShareAccess -Name VMFiles `  -AccountName "Contoso\Domain Admins" `  -AccessRight Change -Force
Output
PS C:\>Block-SmbShareAccess -Name VMFiles -AccountName Contoso\GuestPerforming operation 'Modify' on Target 'Contoso-SO,VMFiles'.Name                    ScopeName               AccountName             AccessControlType       AccessRight----                    ---------               -----------             -----------------       -----------VMFiles                 Contoso-SO              Contoso\Guest           Deny                    FullVMFiles                 Contoso-SO              Contoso\Administrator   Allow                   FullVMFiles                 Contoso-SO              Contoso\Domain Admins   Allow                   Change

224.5 Close-SmbOpenFile (13) + Close-SmbSession (11)

  • Close-SmbOpenFile forcibly closes one file (-FileId) or all files of a session (-SessionId).
  • Close-SmbSession ends the whole session; without -Force it asks for confirmation.
  • Docs: unsaved changes can be lost, so talk to the user first.
PowerShell
Close-SmbOpenFile -FileId 4415226383589Close-SmbOpenFile -SessionId 4415226380393Get-SmbOpenFile |  Where-Object -Property ShareRelativePath `  -Match "\.DOCX" | Close-SmbOpenFile -ForceClose-SmbSession -SessionId 8813272891621
Output
PS C:\>Close-SmbSession -SessionId 8813272891621ConfirmAre you sure you want to perform this action?Performing operation 'Close-Session' on Target '8813272891621'.[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): N

224.6 Get-SmbSession (12) + Get-SmbOpenFile (13)

  • Get-SmbSession: session ID, client IP, user, dialect and open count of every client.
  • Get-SmbOpenFile: path, client, user and session of every open file; answers 'who is holding this file?'.
  • Filters: -ClientComputerName, -ClientUserName, -SessionId, -ScopeName.
PowerShell
Get-SmbSessionGet-SmbSession -ClientComputerName `  "192.168.102.14"Get-SmbSession -SessionId 8813272891441 |  Select-Object -Property *Get-SmbOpenFile -FileId 4415226383569 |  Select-Object -Property *Get-SmbOpenFile |  Where-Object -Property ShareRelativePath `  -Match ".VHDX"
Output
PS C:\>Get-SmbSession -SessionId 8813272891441 | Select-Object -Property *ClientComputerName    : 192.168.101.13ClientUserName        : Contoso\Contoso-HV1$Dialect               : 3.00NumOpens              : 1ScopeName             : Contoso-FSSecondsExists         : 45346SecondsIdle           : 33SessionId             : 8813272891441 PS C:\>Get-SmbOpenFile -FileId 4415226383569 | Select-Object -Property *ClientComputerName    : 192.168.102.14ClientUserName        : Contoso\Contoso-HV2$FileId                : 4415226383569Locks                 : 1Path                  : C:\ClusterStorage\Volume2\VMS\VM4.VHDXScopeName             : Contoso-SOSessionId             : 4415226380393ShareRelativePath     : VM4.VHDX

224.7 Get-SmbShare (25) + Get-SmbShareAccess (6)

  • Get-SmbShare lists all shares, including default ADMIN$, C$ and IPC$; most of its 25 options are filters (-EncryptData, -CachingMode, -ShareState, -ContinuouslyAvailable...).
  • Get-SmbShare -CimSession NEDFS1 runs it against a remote server.
  • Get-SmbShareAccess shows the share ACL: which account has which access.
PowerShell
Get-SmbShareGet-SmbShare -Name "VMS1" |  Format-List -Property *Get-SmbShareAccess -Name "VMFiles"
Output
Get-SMBShareName                          ScopeName                     Path                          Description----                          ---------                     ----                          -----------ADMIN$                        *                             C:\\Windows                   Remote AdminC$                            *                             C:\\                          Default shareIPC$                          *                                                           Remote IPCVMS1                          *                             I:\VMS Get-SmbShare -Name "VMS1" | Format-List -Property *ShareState            : OnlineAvailabilityType      : ClusteredFolderEnumerationMode : UnrestrictedCachingMode           : ManualContinuouslyAvailable : TrueCurrentUsers          : 3EncryptData           : FalsePath                  : I:\VMS

224.8 Client-side and configuration cmdlets

CmdletShows
Get-SmbConnection (5)Client connections: server, share, user, dialect, NumOpens
Get-SmbMapping (4)Client drive mappings (X: -> \\Contoso-SO\VMFiles)
Get-/New-SmbGlobalMapping (3/17)Mappings for all users (main use: Windows Containers); -RequirePrivacy, -RequireIntegrity, -Persistent
Get-SmbClient/ServerNetworkInterfaceNICs SMB uses (RSS/RDMA capable, speed)
Get-SmbMultichannelConnection (7) / Constraint (2)Parallel client-server interface pairs; allowed interfaces per server
Get-SmbClient/ServerConfiguration (1)All settings in one list, no filters
Enable/Disable/Get-SmbDelegationLets a remotely logged-in user on a client work on a remote SMB server
Get-SmbBandwidthLimit (3)Bandwidth cap per category (Default, VirtualMachine, LiveMigration, StorageReplication)
Get-SmbServerAlternativePort, CertProps, CertificateMappingSMB over QUIC: port 443, certificate test, cert-to-name mapping
PowerShell
Get-SmbConnectionGet-SmbMultichannelConnection `  -ServerName "Contoso-SO"$creds = Get-CredentialNew-SmbGlobalMapping `  -RemotePath "\\fs1.contoso.com\public" `  -Credential $creds -LocalPath "G:"Get-SmbServerConfiguration
Output
PS C:\>Get-SmbConnectionServerName          ShareName           UserName             Credential           Dialect             NumOpens----------          ---------           --------             ----------           -------             --------Contoso-FS1         VMS5                Contoso\Contoso-HV1$ Contoso\Contoso-HV1$ 3.00                1Contoso-FS          VMS1                Contoso\Contoso-HV1$ Contoso\Contoso-HV1$ 3.00                1 PS C:\>Get-SmbMultichannelConnection -ServerName "Contoso-SO"Server Name    Selected       Client IP      Server IP      Client         Server         Client RSS     Client RDMA-----------    --------       ---------      ---------      -------------- -------------- -------------- --------------Contoso-SO     True           192.168.102.13 192.168.102.11 15             15             False          TrueContoso-SO     True           192.168.101.13 192.168.101.11 12             12             False          True Status Local Path Remote Path------ ---------- -----------OK     G:         \\fs1.contoso.com\public Get-SmbServerConfigurationEnableSMB1Protocol                     : FalseEnableSMB2Protocol                     : TrueEncryptData                            : FalseRejectUnencryptedAccess                : TrueRequireSecuritySignature               : FalseEnableSMBQUIC                          : True
  • In a security audit check EnableSMB1Protocol (should be False), RequireSecuritySignature and EncryptData.
  • To change settings you use Set-SmbClientConfiguration / Set-SmbServerConfiguration (part 3).

224.9 Linux equivalent: Samba lab

Windows cmdletSamba equivalent
Get-SmbSharesmbclient -L //filesrv
Get-SmbSession / Get-SmbOpenFilesmbstatus (sessions, shares, locked files)
Close-SmbOpenFilesmbcontrol smbd close-share docs
Close-SmbSessionsmbcontrol smbd kill-client-ip
Block-SmbShareAccesshosts deny in smb.conf + reload-config
Terminal
smbclient -L //filesrv -U asha%LabPass224smbstatussmbcontrol smbd close-share docssmbcontrol smbd kill-client-ip 192.168.244.22# smb.conf [docs]:#   hosts deny = 192.168.244.22smbcontrol smbd reload-configsmbclient //filesrv/docs -U ravi%RaviPass224 -c ls
Output
[asha] $ smbclient -L //filesrv -U asha%LabPass224	Sharename       Type      Comment	---------       ----      -------	docs            Disk      Team documents	public          Disk      Read-only public files	IPC$            IPC       IPC Service (N224 lab file server) [srv] $ smbstatus   (trimmed)PID     Username     Group        Machine                                   Protocol Version78      asha         asha         192.168.244.21 (ipv4:192.168.244.21:45600) SMB3_1179      ravi         ravi         192.168.244.22 (ipv4:192.168.244.22:53706) SMB3_11Locked files:Pid          User(ID)   DenyMode   Access      R/W        Oplock           SharePath   Name   Time78           1000       DENY_NONE  0x3         RDWR       NONE             /srv/docs   report.txt   Mon Nov  9 14:54:05 2026 [srv] $ smbstatus -LNo locked files[asha] $ smbclient //filesrv/docs -U asha%LabPass224 -c ls  report.txt                          N       18  Mon Nov  9 14:53:51 2026 [ravi] $ smbclient //filesrv/docs -U ravi%RaviPass224 -c lstree connect failed: NT_STATUS_ACCESS_DENIED(exit 1)
  • After close-share and kill-client-ip both clients reconnected immediately and ls worked.
  • Only hosts deny actually stopped ravi on docs; his public share and asha's access stayed normal.

224.10 Common mistakes

  • Assuming Close-SmbSession throws the user out; the client simply reconnects. Use a block to stop someone.
  • Closing an open file without telling the user; unsaved data can be lost.
  • Running Get cmdlets on an office server and pasting the output: it reveals server and user names.
  • Forgetting that share permission and NTFS permission combine; the stricter one wins.

224.11 Interview tips

  • Who is connected and which files are open: Get-SmbSession (IP, user, open count) and Get-SmbOpenFile (path, user, session).
  • Locked file: find it with Get-SmbOpenFile, then Close-SmbOpenFile after talking to the user.
  • Close ends a connection, Block denies, Grant allows.
  • Client side: Get-SmbConnection, Get-SmbMapping; server side: Get-SmbSession, Get-SmbOpenFile, Get-SmbShare.
  • Linux Samba: smbstatus + smbcontrol + hosts deny.