Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function export-import-plex {
- param (
- [switch]$Import
- , [string]$importPath = "$($env:USERPROFILE)\Desktop\plex.zip"
- , [string]$exportPath = "$($env:USERPROFILE)\Desktop\plex.zip"
- )
- $plexPath = "$($env:LOCALAPPDATA)\Plex Media Server"
- $reg = Get-Item -Path "$env:windir\system32\reg.exe"
- $regPath = 'HKCU\Software\Plex, Inc.'
- if ($import) {
- if (!(Test-Path -Path $importPath)) {
- Write-Host -f Red "$importPath does not exist, try again"
- Pause
- break;
- }
- #unzipping files
- Write-Host -ForegroundColor Yellow "Importing Plex"
- Expand-Archive -LiteralPath $importPath -DestinationPath (Split-Path $plexPath)
- #import Regsettings
- Start-Process -FilePath $reg.FullName -ArgumentList "import `"$($plexPath)\plex.reg`"" -Verb runAs -WindowStyle Hidden
- Write-Host -ForegroundColor Yellow "Plex import complete"
- } else {
- # close plex before compress
- Get-Process | where {$_.name -match 'plex'} | Stop-Process -Force -ErrorAction SilentlyContinue
- Start-Process -FilePath $reg.FullName -ArgumentList "export `"$regPath`" `"$($plexPath)\plex.reg`"" -Verb runAs -WindowStyle Hidden
- Write-Host -ForegroundColor Yellow "Backing up Plex"
- Compress-Archive -LiteralPath $plexPath -DestinationPath $exportPath -CompressionLevel Fastest -Force
- Write-Host -ForegroundColor Yellow "Backup complete"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement