How to Use Windows PowerShell ‘Get-SmbShare’ for Network File Sharing

The Network Share Problem

In a Windows corporate environment, data is rarely stored on local C: drives. It is stored on massive File Servers and broadcast across the network via SMB (Server Message Block) shares.

If an auditor asks an IT Administrator, “Can you show me every single hidden network share broadcasting from this server?”, the traditional method is to open the graphical “Computer Management” console, click “Shared Folders,” and click “Shares.”

This graphical method is useless if you need to audit 50 different servers simultaneously. To programmatically extract, create, and manage network shares across an enterprise, administrators use the PowerShell SMB Share cmdlets, anchored by Get-SmbShare.

1. Auditing Broadcasts (Get-SmbShare)

To see every single folder that a specific Windows Server is currently broadcasting to the network, simply open an elevated PowerShell prompt and type:

Get-SmbShare

This outputs a clean table showing the Name of the share (what the users see), the Path (where the folder physically lives on the hard drive), and the Description.

Crucially, you will also see the hidden administrative shares (like C$ and IPC$) which are normally invisible to standard users but represent massive security vectors if improperly configured.

2. Creating New Shares (New-SmbShare)

If you are deploying a brand new File Server, you do not want to manually right-click 100 different folders and select “Share.” You can script the entire deployment.

To broadcast the C:\Corporate\HR_Data folder to the network under the name “HR_Department”:

New-SmbShare -Name "HR_Department" -Path "C:\Corporate\HR_Data" -Description "Confidential HR Files"

The Share Permission Warning:
By default, creating a share grants “Everyone” Read access at the share level. In modern Windows architecture, you should leave the Share Permissions wide open (Everyone = Full Control) and rely entirely on strict NTFS permissions (Get-Acl/Set-Acl) to actually secure the folder. However, if you must restrict the share level natively:

New-SmbShare -Name "Finance" -Path "C:\Corporate\Finance" -FullAccess "CORP\FinanceGroup"

3. Managing Active Connections (Get-SmbSession)

If you need to reboot a File Server in the middle of the day, you must know if anyone is currently using it. If you reboot while the CEO is saving a massive Excel file, the file will corrupt.

You can audit the live, active network connections to the server:

Get-SmbSession

This will output the IP Address, the exact Username, and the number of files they currently have locked open over the network.

If you see a user connected, you can look deeper to see exactly which specific files they are holding hostage using Get-SmbOpenFile. If a user goes home for the weekend leaving a critical database file locked open, you can forcefully sever their connection to free the file:

Close-SmbOpenFile -ClientUserName "CORP\JSmith" -Force

Conclusion

The SMB cmdlets replace the tedious, click-heavy Computer Management console. By allowing administrators to instantly audit hidden broadcasts, programmatically deploy new network drives, and surgically sever locked file connections, Get-SmbShare and its companion cmdlets are essential for managing enterprise file infrastructure.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.