Get-FileShares PowerShell function will enumerate all shares (except administrative, but including those that end in a dollar sign ($) on a remote machine and optionally send the output to a CSV file.
The following share properties will be included in the export:
ServerName | ShareName | SharePath | Description
ServerName | ShareName | SharePath | Description |
FILESERVER01 | \\FILESERVER01\CustomerCare | E:\Groups\CustomerCare | Customer Care Group Share |
FILESERVER01 | \\FILESERVER01\Groups_E$ | E:\Groups\ | Group Share Drive E: |
FILESERVER01 | \\FILESERVER01\Software$ | D:\Software | Hidden share for DCA use |
Parameters
-servername
Defines the name of the target server
-export
Specifies the path of the exported CSV file
Syntax
1 |
.\Get-FileShares.ps1 -servername FILESERVER01 -export c:\exports |
or simply
1 |
.\Get-FileShares.ps1 FILESERVER01 c:\exports |
This will generate a file c:\exports\FILESERVER01_Shares_01-15-2015.csv
Download Link
The Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
param ( [Parameter(Mandatory=$True, HelpMessage='Please specify the Server Name (e.g. FILESERVER01)')] [string]$servername, [Parameter(Mandatory=$False, HelpMessage='Please specify the CSV export path (e.g. c:\temp)')] [string]$export ) $shareColl = @()#Makes an array, or a collection to hold all the object of the same fields. $Shares = Get-WmiObject -ComputerName $servername -Class Win32_Share -filter "Type=0 AND name like '%$'" foreach ($share in $shares) { $shareObject = New-Object PSObject #An object, created and destroyed for each share. Add-Member -inputObject $shareObject -memberType NoteProperty -name "ServerName" -Value $servername Add-Member -inputObject $shareObject -memberType NoteProperty -name "ShareName" -Value $share.Name Add-Member -inputObject $shareObject -memberType NoteProperty -name "SharePath" -Value $share.Path Add-Member -inputObject $shareObject -memberType NoteProperty -name "Description" -Value $share.Description $shareObject #Output to the screen for a visual feedback. $shareColl += $shareObject #Copy the contents of the object into the Array (Collection) #$shareObject = $null #Delete the shareObject. } if ($export) { $shareColl | Export-Csv -path "$export\$($servername)_Shares_$((Get-Date).ToString('MM-dd-yyyy')).csv" -NoTypeInformation } |


