PowerShell Get List Of Folders Shared
Try this:
get-WmiObject -class Win32_Share -computer dc1.krypted.com
Ref: List Shares in Windows w/ PowerShell
There's only one way of enumerating shares remotely from the command line that I know of, and thats with net view
:
C:\Users\mark.henderson>net view \\enetsqnap01
Shared resources at \\enetsqnap01
Share name Type Used as Comment
-------------------------------------------------------------------------------
Backups Disk
CallRecordings Disk
Download Disk System default share
home Disk Home
homes Disk System default share
Installs Disk
Justin Disk Copy of files from Justin laptop
michael Disk
Multimedia Disk System default share
Network Recycle Bin 1 Disk [RAID5 Disk Volume: Drive 1 2 3 4]
Public Disk System default share
Qsync Disk Qsync
Recordings Disk System default share
Sales Disk Sales Documents
SalesMechanix Disk
Server2012 Disk Windows Server 2012 Install Media
Usb Disk System default share
VMWareTemplates Disk
Web Disk System default share
The command completed successfully.
This is not particularly parsable on its own, but, you can throw it into an array to process the data line by line:
$sharedFolders = (NET.EXE VIEW \\enetsqnap01)
You now have an array, and starting at $sharedFolders[7]
you have your shares. You could then split
on something like a double space - unlikely to appear in a share name itself, and should work unless your share name is very long, only leaving a single space between the share name and the type field:
$sharedFolders[7].split(' ')[0]
Backups
You could process these by using a ForEach and some conditional logic. It wouldn't be perfect, but it should work for most use cases.
For brevity, to just output the filenames to the console:
(net view \\enetsqnap01) | % { if($_.IndexOf(' Disk ') -gt 0){ $_.Split(' ')[0] } }
If you want to find the shares of the local machine you can just do Get-SmbShare
:
> Get-SmbShare
Name ScopeName Path Description
---- --------- ---- -----------
ADMIN$ * C:\WINDOWS Remote Admin
C$ * C:\ Default share