Skip to content

PowerShell automation script for setting up network shares for legacy scanners with firewall and user management

Notifications You must be signed in to change notification settings

MbarekTech/powershell-network-share-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Share Folder Scanner Setup

Quick PowerShell script to create network shares for legacy scanners. Saves you from clicking through Windows sharing dialogs and firewall settings.

Why This Exists

Got an old scanner that needs to save files to a network folder? This script handles the Windows setup automatically - firewall rules, user accounts, folder permissions, the works. Takes 30 seconds instead of 10 minutes of clicking around.

What It Does

  • Creates a Scan folder on your desktop
  • Sets up SMB sharing with proper permissions
  • Creates a scan user (password: scan) for scanner login
  • Configures Windows firewall to allow file sharing
  • Sets network profile to Private (required for sharing)
  • Optional detailed logging to scanner-setup.log (enabled by default)
  • Optional tracking of shared paths in list.txt (disabled by default)

Quick Start

  1. Download and run the script (will ask for admin rights)
  2. Point your scanner to \\YOUR-PC-NAME\scan
  3. Use username scan and password scan

That's it. Your scanner can now save files to the desktop Scan folder.

Advanced Usage

Default behavior (no logging, no list.txt):

.\Setup-ShareFolder-Scanner.ps1

Enable logging and create list.txt:

.\Setup-ShareFolder-Scanner.ps1 -EnableLog -CreateListFile

Clean operation (minimal files):

.\Setup-ShareFolder-Scanner.ps1

Custom credentials:

.\Setup-ShareFolder-Scanner.ps1 -Username "scanner" -Password (Read-Host -AsSecureString)

Configuration file setup:

.\Setup-ShareFolder-Scanner.ps1 -ConfigFile "config.json"

Test connection after setup:

.\Setup-ShareFolder-Scanner.ps1 -TestConnection

Remove scanner share and user:

.\Setup-ShareFolder-Scanner.ps1 -Cleanup

Get help:

Get-Help .\Setup-ShareFolder-Scanner.ps1 -Full

Features

  • Auto-elevation: Automatically requests administrator privileges
  • Smart defaults: No logging, no list.txt by default for clean operation
  • Configuration files: JSON configuration support for enterprise deployments
  • Custom credentials: Support for custom username/password combinations
  • Connection testing: Built-in share connectivity validation with -TestConnection
  • Cleanup mode: Easy removal of scanner components with -Cleanup
  • Comprehensive logging: Optional detailed logs in scanner-setup.log
  • Error handling: Automatic rollback on failures with resource tracking
  • Configuration validation: Verifies everything works after setup
  • Share conflict resolution: Handles existing share name conflicts
  • Legacy compatibility: SMB settings optimized for old scanners

Installation

  1. Download the Setup-ShareFolder-Scanner.ps1 file
  2. Right-click and "Run with PowerShell" (or run from command line)
  3. Click "Yes" when Windows asks for admin privileges

Configuration Files

Create a JSON configuration file for enterprise deployments:

{
    "Username": "scanner",
    "FolderName": "ScannerShare",
    "FolderPath": "C:\\SharedScan",
    "EnableLog": true
}

Use with: .\Setup-ShareFolder-Scanner.ps1 -ConfigFile "config.json"

Configuration options:

  • Username: Custom scanner user account name
  • FolderName: Custom share and folder name
  • FolderPath: Custom path for the shared folder
  • EnableLog: Enable detailed logging (true/false)

Files Created

  • Scanner folder: %USERPROFILE%\Desktop\Scan (scan destination)
  • Log file: scanner-setup.log (optional detailed operation log, disabled by default)
  • List file: list.txt (optional share tracking with -CreateListFile, disabled by default)
  • Config file: Custom JSON configuration files (when using -ConfigFile)

Tested With

Works with most office scanners and multifunction printers that support SMB/CIFS, including older Canon, HP, Xerox, and Ricoh models.

Security Note

Uses simple credentials (scan/scan) because that's what most legacy scanners expect. The shared folder only allows access from your local network. Change the password in the script if needed.

Troubleshooting

Common Scanner Connection Issues

Scanner can't connect?

  • Check that both devices are on the same network
  • Try using the computer's IP address instead of name: \\192.168.1.100\Scan
  • Verify the scanner supports SMB v1/v2 protocol
  • Make sure Windows firewall isn't blocking connections
  • Test from another device: \\COMPUTER-NAME\Scan

"Access Denied" errors?

  • Ensure you're using the correct credentials: scan / scan
  • Try connecting from Windows Explorer first to test
  • Check if the share exists: Get-SmbShare -Name Scan
  • Verify user permissions: Get-SmbShareAccess -Name Scan

Script won't run?

  • Right-click the file and check "Unblock" if downloaded from internet
  • Make sure you're running PowerShell as administrator
  • Check PowerShell execution policy: Get-ExecutionPolicy
  • Try: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Scanner-Specific Tips

Canon Printers: Use SMB v1, try IP address format HP MFPs: Usually work with default settings, may need SMB v2 Xerox/Ricoh: Often require exact computer name, not IP Brother: May need manual port 445 verification

Network Diagnostics

# Test if SMB service is running
Get-Service -Name LanmanServer

# Check if port 445 is open
Test-NetConnection -ComputerName localhost -Port 445

# List all shares
Get-SmbShare

# Test share access
net use * \\localhost\Scan /user:scan scan

Requirements

  • Windows 7 or later
  • PowerShell (comes with Windows)
  • Local network connection

Made this because setting up scanner shares manually is tedious. Hope it saves you some time.

About

PowerShell automation script for setting up network shares for legacy scanners with firewall and user management

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published