Advertisement
upz

Export-Import Plex - windows

upz
Aug 15th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function export-import-plex {
  2.     param (
  3.             [switch]$Import
  4.         ,   [string]$importPath = "$($env:USERPROFILE)\Desktop\plex.zip"
  5.         ,   [string]$exportPath = "$($env:USERPROFILE)\Desktop\plex.zip"
  6.     )
  7.  
  8.     $plexPath = "$($env:LOCALAPPDATA)\Plex Media Server"
  9.     $reg = Get-Item -Path "$env:windir\system32\reg.exe"
  10.     $regPath = 'HKCU\Software\Plex, Inc.'
  11.  
  12.     if ($import) {
  13.  
  14.         if (!(Test-Path -Path $importPath)) {
  15.             Write-Host -f Red "$importPath does not exist, try again"
  16.             Pause
  17.             break;
  18.         }
  19.  
  20.         #unzipping files
  21.         Write-Host -ForegroundColor Yellow "Importing Plex"
  22.         Expand-Archive -LiteralPath $importPath -DestinationPath (Split-Path $plexPath)
  23.  
  24.         #import Regsettings
  25.         Start-Process -FilePath $reg.FullName -ArgumentList "import `"$($plexPath)\plex.reg`"" -Verb runAs -WindowStyle Hidden
  26.         Write-Host -ForegroundColor Yellow "Plex import complete"
  27.  
  28.     } else {
  29.  
  30.         # close plex before compress
  31.         Get-Process | where {$_.name -match 'plex'} | Stop-Process -Force -ErrorAction SilentlyContinue
  32.         Start-Process -FilePath $reg.FullName -ArgumentList "export `"$regPath`" `"$($plexPath)\plex.reg`"" -Verb runAs -WindowStyle Hidden
  33.  
  34.         Write-Host -ForegroundColor Yellow "Backing up Plex"
  35.         Compress-Archive -LiteralPath $plexPath -DestinationPath $exportPath -CompressionLevel Fastest -Force
  36.         Write-Host -ForegroundColor Yellow "Backup complete"
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement