Skip to content

How to Create a Secure SMB Share with PowerShell Print

  • 0

Applies to: Windows Server 2019, Windows Server 2022 and Windows Server 2025, subject to the workload and edition requirements below.

A secure share has two permission layers

An SMB share exposes an existing folder to network clients. Its effective access depends on the user identity, share permissions and the NTFS permissions of the requested object. Both layers must allow the operation. Access-based enumeration changes what users see in a directory listing; it does not replace authorization. A folder hidden from one view may still be requested directly, so its ACL must remain correct.

This walkthrough builds a new Finance share for an AD domain using separate read and modify groups. It deliberately avoids replacing permissions on an established production tree. For existing data, first export ACLs, review ownership and inheritance, and plan a migration or controlled ACL change. A command that is appropriate for an empty folder may cause a major access outage when applied recursively to years of departmental data.

Prepare the directory and security groups

Install the File Server role, verify the data volume, and identify the exact domain NetBIOS name. In these examples CORP is illustrative. Create or confirm Domain Local resource groups such as DL-Finance-Read and DL-Finance-Modify, with users assigned through approved role groups. The person requesting a share should identify its owner, retention needs and whether authorized staff may delete files as part of Modify access.

Use an elevated Windows PowerShell session on FS01. Confirm that Finance is not already a share name and that the target folder is genuinely new. Choose an NTFS volume and a backup policy before putting sensitive documents there. Record whether offline caching is permitted; cached documents on laptops introduce a separate device-protection and revocation consideration.

Get-SmbShare -Name Finance -ErrorAction SilentlyContinue
Get-Volume -DriveLetter D
Test-Path -LiteralPath 'D:\Shares\Finance'

Build a deliberate NTFS ACL on an empty folder

Create the folder and inspect inherited permissions. The example below is intended only for a new, empty directory. It removes inherited entries from that boundary and adds explicit entries for SYSTEM, local Administrators and the two resource groups. The well-known SIDs avoid depending on the display language of the local administration group.

$path = 'D:\Shares\Finance'
New-Item -ItemType Directory -Path $path -ErrorAction Stop | Out-Null
icacls $path /inheritance:r
icacls $path /grant:r '*S-1-5-18:(OI)(CI)F' '*S-1-5-32-544:(OI)(CI)F' 'CORP\DL-Finance-Read:(OI)(CI)RX' 'CORP\DL-Finance-Modify:(OI)(CI)M'
if ($LASTEXITCODE -ne 0) { throw 'Review the ACL command result before proceeding.' }
icacls $path

OI and CI make the permissions inheritable by files and subdirectories. RX grants read and execute; M grants modify, including normal deletion. F is retained for the system and authorized administrators. The command does not make business users owners and does not authorize them to rewrite all ACLs. If the new-item command reports that the directory already exists, stop and review it rather than adding Force and continuing blindly.

Publish only the intended access

Use Change at the share layer for the modify group and Read for the read group. NTFS still determines detailed file access. An administration group receives share Full access for maintenance, while the underlying ACL retains its own administration entry. Requiring encryption protects SMB traffic on this share; confirm that all intended clients support SMB 3 encryption before rollout.

New-SmbShare -Name 'Finance' -Path $path `
  -ReadAccess 'CORP\DL-Finance-Read' `
  -ChangeAccess 'CORP\DL-Finance-Modify' `
  -FullAccess 'BUILTIN\Administrators' `
  -FolderEnumerationMode AccessBased `
  -CachingMode None -EncryptData $true `
  -Description 'Finance documents; access through approved AD groups'

If the local Administrators display name differs on this server, resolve and use its actual name. Do not use Everyone Full Control as a shortcut for an unresolved identity. CachingMode None turns off Offline Files caching through this share; it does not stop users from making ordinary copies. Review any created permissions immediately and remove an unexpected broad entry before onboarding clients.

Check configuration and actual user behaviour

Review the published path, encryption, enumeration mode and permission entries. Confirm the share points to Finance rather than a parent folder containing other departments. There should be no accidental anonymous or guest access. Then use the server FQDN in a UNC path, such as \fs01.corp.example\Finance, from an approved workstation.

Get-SmbShare -Name Finance | Format-List Name,Path,EncryptData,FolderEnumerationMode,CachingMode
Get-SmbShareAccess -Name Finance
Get-Acl -LiteralPath $path | Format-List Owner,AccessToString

Test a reader, a modifier and a user outside both groups. The reader should enumerate allowed content and open a file but fail to create, change or delete one. The modifier should create a test subfolder, edit a test file and delete it if that is the approved workflow. The unrelated account should receive access denied. Perform the tests with disposable test content and record the actual account used. Administrator success alone is insufficient.

Avoid misleading permission tests

Windows can reuse a connection to the same server under existing credentials, and access tokens contain group memberships from sign-in. A newly added group membership may therefore not appear in the session being tested. Use a fresh sign-in or isolated test client. Before disconnecting a mapped drive, check for open files and ensure the test will not interrupt somebody’s work. Do not indiscriminately clear all network connections on a production session.

Membership in both read and modify groups normally yields the union of allowed rights, subject to applicable denies and the other permission layer. Explicit Deny entries can block access through an unexpected group and complicate administration. Use a clear allow-based model where possible. The Effective Access tab can help inspect NTFS results, but an actual network test remains necessary because the share layer and authentication context also matter.

Troubleshoot by layer

For a network-path error, validate DNS, the share name and TCP 445 reachability before changing permissions. For access denied, identify the connecting account, examine Get-SmbShareAccess and inspect the requested child object’s ACL, not only the top-level directory. A file with disabled inheritance can behave differently from adjacent files. Check parent traversal and whether a file is locked if reading works but modification fails.

If an older appliance cannot connect, determine its SMB dialect, encryption support and authentication capabilities. Windows Server 2025 introduces stronger SMB defaults than older deployments. Do not resolve a compatibility issue by enabling SMB1, guest access or disabling signing across the server. Use a supported client upgrade or a separately assessed integration path. When encryption is required, inspect Get-SmbConnection on the Windows client to verify the negotiated connection rather than relying on a green network icon.

Rollback without deleting business data

If the new share exposes the wrong path or users receive unexpected access, remove the share from service while preserving its files. Remove-SmbShare -Name Finance stops publication; it does not delete D:\Shares\Finance or repair its ACL. Notify users first because existing sessions and open files may be interrupted. Retain the data and evidence while correcting the configuration.

For an existing share, restore the recorded share settings and ACLs through a reviewed change; do not apply a new empty-folder ACL to the entire tree. Establish recurring access reviews, capacity alerts and restore tests. Share permissions are only one part of protecting financial documents: backup isolation, endpoint security, encryption at rest where appropriate, and accountable group ownership must support the same data-handling requirements.

Related guidance and official references

Install the File Server role; Design AGDLP permissions; Require SMB encryption.


Was this answer helpful?

« Back