Skip navigation
View all shares on remote machine with PowerShell

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.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish