View all shares on remote machine with PowerShell

List shares on remote machines using PowerShell.

John Savill

December 4, 2015

1 Min Read
View all shares on remote machine with PowerShell

For more technical explainers on PowerShell, read our updated 2021 report: PowerShell 101: A Technical Explainer for IT Pros.

Q. How can I view all shares on a remote machine with PowerShell?

A. To view local shares using PowerShell use:

Get-SmbShare

To view shares on a remote server create a CIM session on the remote box then use it. For example:

$cim = New-CimSession -ComputerName savdaldc02
Get-SmbShare -CimSession $cim

Another approach would be to use the net view information but is a more complex PowerShell command but avoids the need for the CIM session. For example:

$shares = net view \savdaldc02 /all | select -Skip 7 | ?{$_ -match 'disk*'} | %{$_ -match '^(.+?)s+Disk*'|out-null;$matches[1]}

Note that this command uses the output from net view, skips the first 7 lines which is the header information then finds lines with the word Disk in them then outputs the share name.

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like