Get List of Network Shares using Powershell script

Description:

We can easily get the list of Network Shares/Share Folder, Devices, Disk Drives and Printers by using WMI class Win32_Share. But it will lists only NTFS Shares, not the Cluster Share Folders. You can use the alternative WMI class Win32_ClusterShare to list Cluster Shares. In this article, I am going write Powershell script samples to get list of Network Shares in Local Machine and Remote Computer.

Summary:

List Network Shares in Local Machine using Powershell

You can enumerate the Network Shares list by using Powerahell‘s WMI class Win32_Share. Here, FT is nothing but the Format-Table cmdlet, you can change it into FL to display result in list view.

Get-WMIObject -Query "SELECT * FROM Win32_Share" | FT
Get List of Network Shares using Powershell script

List Network Shares from Remote Computer using Powershell

You can list the Network Shares from Remote Machine by giving name of the remote computer through argument syntax -ComputerName.

Get-WMIObject -ComputerName "your-pc" -Query "SELECT * FROM Win32_Share" | FL
List Network Shares from Remote Computer using Powershell script

List only Network Share Folders (Not hidden shares) using Powershell

You can use SQL Query like syntax to apply filter in Win32_Share class. The following Powershell script, filters and list only Network Share Folders (Not hidden shares) by adding filter Type=0.

Get-WMIObject -ComputerName "your-pc" -Query "SELECT * FROM Win32_Share Where Type=0" | FT
List only Network Share Folders (Not hidden) using Powershell script

Export Network Shares to CSV using Powershell

You can export the Network Shares list into CSV using Powershell‘s Export-CSV cmdlet. The following script exports not hidden Network Share Folders to CSV file from Remote Computer.

Get-WMIObject -ComputerName "your-pc"`
 -Query "SELECT * FROM Win32_Share Where Type=0" |
 Select-Object Name,Path,Description |
 Export-CSV 'C:\NetworkShares.csv'
Export Network Shares to CSV file using Powershell script

Thanks,
Morgan


Advertisement

2 thoughts on “Get List of Network Shares using Powershell script”

  1. hello, when i use the command it says acces denied

    I’m on windows server 2016 and trying to see share on a windows 10

    I’m administrator and all firewall have been disable

    Reply

Leave a Comment