A PowerShell module for managing Plex Media Servers through automation and scripting.
PlexAutomationToolkit provides a comprehensive set of cmdlets for automating Plex server management tasks, including server configuration, library operations, and content browsing. Whether you're managing a single server or multiple Plex instances, this module simplifies common automation workflows.
- Server Management: Add, remove, and configure multiple Plex server connections with default server support
- Authentication Support: Optional X-Plex-Token authentication for secured servers
- Library Operations:
- List and query library sections
- Refresh entire libraries or specific paths
- Browse library content and resolve filesystem paths
- Tab completion for library names and paths
- Pipeline Support: All cmdlets follow PowerShell conventions for pipeline operations
- Error Handling: Consistent error messages with
-WhatIfand-Confirmsupport for destructive operations
- PowerShell 5.1 or higher
- Network access to your Plex Media Server
- Plex authentication token (optional, for secured servers)
Install-Module -Name PlexAutomationToolkit -Scope CurrentUser# Clone the repository
git clone https://github.com/tablackburn/PlexAutomationToolkit.git
cd PlexAutomationToolkit
# Install build dependencies
./build.ps1 -Bootstrap
# Build and test the module
./build.ps1 -Task Test
# Import the built module
Import-Module ./Output/PlexAutomationToolkit/0.1.0/PlexAutomationToolkit.psd1# Add server without authentication (local network)
Add-PatServer -Name "Main Server" -ServerUri "http://plex.local:32400" -Default
# Add server with authentication token
Add-PatServer -Name "Remote Server" -ServerUri "http://plex.example.com:32400" -Token "YOUR_TOKEN_HERE" -Default# Get all libraries from default server
Get-PatLibrary
# Get specific library section
Get-PatLibrary -SectionId 1# Refresh entire library by ID
Update-PatLibrary -SectionId 2
# Refresh entire library by name (with tab completion!)
Update-PatLibrary -SectionName "Movies"
# Refresh specific path within a library
Update-PatLibrary -SectionName "Movies" -Path "/mnt/media/Movies/New Releases"# Add multiple servers
Add-PatServer -Name "Main" -ServerUri "http://192.168.1.100:32400" -Default
Add-PatServer -Name "Remote" -ServerUri "https://remote.example.com:32400" -Token "abc123"
# List configured servers
Get-PatStoredServer
# Get only the default server
Get-PatStoredServer -Default
# Change default server
Set-PatDefaultServer -Name "Remote"
# Remove a server
Remove-PatServer -Name "Main"# Get server identity and capabilities
Get-PatServer -ServerUri "http://plex.local:32400"
# Get server info from default configured server
Get-PatServer# List all library sections
$libraries = Get-PatLibrary
$libraries.Directory | Select-Object title, type, key
# Get library root paths
Get-PatLibraryPath -SectionId 1
# Browse library content by path
Get-PatLibraryChildItem -Path "/mnt/media/Movies"
# Browse library content by section
Get-PatLibraryChildItem -SectionId 1
Get-PatLibraryChildItem -SectionName "TV Shows"
# Refresh entire library
Update-PatLibrary -SectionId 2 -Confirm:$false
# Refresh specific path (useful after adding new media)
Update-PatLibrary -SectionName "Movies" -Path "/mnt/media/Movies/Action"
# Use -WhatIf to preview changes
Update-PatLibrary -SectionId 1 -WhatIf# Query specific server (overrides default)
Get-PatLibrary -ServerUri "http://other-server:32400"
# Refresh library on specific server
Update-PatLibrary -ServerUri "http://other-server:32400" -SectionId 1
# Get server info without adding to configuration
Get-PatServer -ServerUri "http://test-server:32400"The module provides intelligent tab completion for common parameters:
# Tab completion for library section names
Update-PatLibrary -SectionName <TAB>
# Shows: "Movies", "TV Shows", "Music", etc.
# Tab completion for library paths
Update-PatLibrary -SectionName "Movies" -Path <TAB>
# Shows root paths and subdirectories as you typePlex authentication is optional if your server allows unauthenticated local network access (default for most local setups). However, tokens are required for:
- Remote access (outside your local network)
- Servers configured to require authentication
- Accessing shared servers
See Plex documentation on local network authentication for details.
Use the built-in helper cmdlet:
# Quick instructions
Get-PatToken
# Detailed step-by-step guide
Get-PatToken -ShowInstructionsOr follow these steps:
- Open https://app.plex.tv in your browser
- Navigate to any media item
- Click the three-dot menu (...) and select "Get Info"
- Click "View XML" at the bottom
- Look for
X-Plex-Tokenin the URL - Copy the token value after
X-Plex-Token=
Official guide: https://support.plex.tv/articles/204059436
# Add server with token
Add-PatServer -Name "MyServer" -ServerUri "http://plex.local:32400" -Token "YOUR_TOKEN_HERE" -DefaultIMPORTANT: Tokens are stored in PLAINTEXT in servers.json:
- Windows:
%USERPROFILE%\Documents\PlexAutomationToolkit\servers.json - Or:
%OneDrive%\Documents\PlexAutomationToolkit\servers.json
Your Plex token grants full access to your Plex account. Best practices:
- Only use on trusted systems
- Never commit
servers.jsonto source control - Never share your token publicly
- Set appropriate file permissions on
servers.json - Revoke tokens by changing your Plex password if compromised
# Run all tests (manifest, help, meta, and integration tests)
./build.ps1 -Task Test
# Run only unit tests
Invoke-Pester -Path tests/Unit/
# Run specific test file
Invoke-Pester -Path tests/Help.tests.ps1Integration tests verify functionality against a live Plex server:
-
Copy the example settings file:
Copy-Item tests/local.settings.example.ps1 tests/local.settings.ps1
-
Edit
tests/local.settings.ps1with your server details:$env:PLEX_SERVER_URI = "http://192.168.1.100:32400" $env:PLEX_TOKEN = "YOUR_TOKEN_HERE"
-
Load settings and run tests:
. ./tests/local.settings.ps1 ./build.ps1 -Task Test
Integration tests are automatically skipped if environment variables are not configured.
See tests/Integration/README.md for detailed setup instructions.
# List available build tasks
./build.ps1 -Help
# Install build dependencies
./build.ps1 -Bootstrap
# Build module
./build.ps1 -Task Build
# Run tests
./build.ps1 -Task Test
# Clean output directory
./build.ps1 -Task Clean| Cmdlet | Description |
|---|---|
Add-PatServer |
Add a Plex server to configuration |
Remove-PatServer |
Remove a server from configuration |
Set-PatDefaultServer |
Set the default server |
Get-PatStoredServer |
Get configured server(s) |
Get-PatServer |
Get server identity and capabilities |
Get-PatToken |
Display instructions for obtaining authentication token |
Get-PatLibrary |
List library sections |
Get-PatLibraryPath |
Get library root filesystem paths |
Get-PatLibraryChildItem |
Browse library content by path or section |
Update-PatLibrary |
Refresh a library section |
For detailed help on any cmdlet:
Get-Help Add-PatServer -Full
Get-Help Update-PatLibrary -ExamplesContributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass (
./build.ps1 -Task Test) - Follow existing code conventions (see
CLAUDE.md) - Submit a pull request
This project follows Semantic Versioning. See CHANGELOG.md for release history.
This project was developed with assistance from Claude by Anthropic.
Copyright (c) Trent Blackburn. All rights reserved.
See LICENSE for license information.
- GitHub Repository: https://github.com/tablackburn/PlexAutomationToolkit
- Plex API Documentation: https://support.plex.tv/articles/201638786-plex-media-server-url-commands/
- Finding Your Token: https://support.plex.tv/articles/204059436
- Local Network Auth: https://support.plex.tv/articles/200890058