How To List All The Shares On A Server Using PowerShell

There’s a few ways to get all of the shared folders on a server, but not all of them work for all versions of Windows Server. You can use the Get-SmbShare cmdlet, or you can make CIM/WMI do the work for you. I’ll show you what I prefer, though.

To use Get-SmbShare on a remote computer, you’ll create a new CIM session.

Then you can pass that CIM session to Get-SmbShare.

But what if the server is (heaven forbid!) older than Windows Server 2012R2? Well, you’d get an error telling you “get-cimclass : The WS-Management service cannot process the request. The CIM namespace win32_share is invalid.“. That won’t do.

Well, luckily for those older servers, you can use Get-WmiObject to retrieve this information.

 

4 thoughts on “How To List All The Shares On A Server Using PowerShell

  1. Instead of using Get-WmiObject you are able to use something like

    $option = New-CimSessionOption -Protocol DCOM
    $session = New-CimSession -SessionOption $option -Computername $computer -Credential $creds

Comments are closed.