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
- List Network Shares from Remote Computer
- List only Network Share Folders (Not hidden shares)
- Export Network Shares List into CSV file
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
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 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
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'
Thanks,
Morgan
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
You can refer the following post to fix the error “Get-WmiObject: Access is denied”
https://morgantechspace.com/2022/09/fix-get-wmiobject-access-is-denied-wmi-powershell.html