Skip to content

Script to Generate a Comprehensive List of Network Shares

The Get-SharesList.ps1 script is designed to retrieve a list of shared resources, such as file shares, from a specified environment. It collects information about the shared locations and outputs relevant data, typically used for monitoring or auditing purposes. This script is useful in scenarios where an administrator needs to analyze or document the shared file systems within a network for security or management purposes.

Here is the script:

$server = “\zagarnas”

$shares = (net view $server | Where-Object { $_ -match ‘Disk’ } | ForEach-Object { $_.Split(’ ’)[0].Trim() })

$results = @()

foreach ($share in $shares) {     # Get the share path     $sharePath = $server + "" + $share

    # Check if the share is accessible     if (Test-Path $sharePath) {         # Get the list of folders in the share         $results += Get-ChildItem -Path $sharePath -Directory | select Name,FullName,LastAccessTime,LastWriteTime     } }

$results | Export-Csv -Path “SharesAndFolders.csv” -NoTypeInformation