Functions/StreamDeck/Export-StreamDeckProfile.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
function Export-StreamDeckProfile { <# .Synopsis Exports Stream Deck Profile .Description Exports one or more Stream Deck profiles .Link Get-StreamDeckProfile .Example Export-StreamDeckProfile #> [OutputType([IO.FileInfo])] param( # The name of the profile [Parameter(ValueFromPipelineByPropertyName)] [string] $Name, # The output path for the profile. # If the output path is not provided, profiles will be backed up to $home [Parameter(ValueFromPipelineByPropertyName)] [string] $OutputPath ) begin { if (-not ('IO.Compression.ZipFile' -as [type])) { Add-Type -AssemblyName System.IO.Compression.Filesystem } } process { $gspSplat = @{Name=$Name} $sdprofiles = @(Get-StreamDeckProfile @gspSplat) if (-not $OutputPath) { $OutputPath = $home } #region Export Profiles foreach ($sdp in $sdprofiles) { $sdpOutputDirectory = Join-Path $outputPath "$($sdp.Name)_Profile" | Join-Path -ChildPath "$($sdp.Guid).sdProfile" $sdpOutputPath = Join-Path $OutputPath "$($sdp.Name).streamDeckProfile" if (-not (Test-Path $sdpOutputDirectory)) { $null = New-Item -ItemType Directory -Path $sdpOutputDirectory if (-not $?) { continue } } Copy-Item -Recurse -Path "$($sdp.Path | Split-Path)$([IO.Path]::DirectorySeparatorChar)*" -Destination $sdpOutputDirectory $manifestPath = Join-Path $sdpOutputDirectory "manifest.json" [IO.File]::ReadAllText("$manifestPath") | ConvertFrom-Json | ForEach-Object { $_.psobject.properties.Remove('DeviceUUID') $_ } | ConvertTo-Json -Depth 100 | Set-Content -Path $manifestPath [IO.Compression.ZipFile]::CreateFromDirectory("$($sdpOutputDirectory | Split-path)", "$sdpOutputPath") Remove-Item -Recurse -Force $sdpOutputDirectory Get-Item -LiteralPath $sdpOutputPath } #endregion Export Profiles } } |