Created
August 12, 2020 05:50
-
-
Save ThomPuiman/eaace3d08f27dfbc422e92fe8698f84d to your computer and use it in GitHub Desktop.
Sitecore K8s Convert License file to base64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ConvertTo-CompressedBase64String { | |
| [CmdletBinding()] | |
| Param ( | |
| [Parameter(Mandatory)] | |
| [ValidateScript({ | |
| if (-Not ($_ | Test-Path) ) { | |
| throw "The file or folder $_ does not exist" | |
| } | |
| if (-Not ($_ | Test-Path -PathType Leaf) ) { | |
| throw "The Path argument must be a file. Folder paths are not allowed." | |
| } | |
| return $true | |
| })] | |
| [string] $Path | |
| ) | |
| $fileBytes = [System.IO.File]::ReadAllBytes($Path) | |
| [System.IO.MemoryStream] $memoryStream = New-Object System.IO.MemoryStream | |
| $gzipStream = New-Object System.IO.Compression.GzipStream $memoryStream, ([IO.Compression.CompressionMode]::Compress) | |
| $gzipStream.Write($fileBytes, 0, $fileBytes.Length) | |
| $gzipStream.Close() | |
| $memoryStream.Close() | |
| $compressedFileBytes = $memoryStream.ToArray() | |
| $encodedCompressedFileData = [Convert]::ToBase64String($compressedFileBytes) | |
| $gzipStream.Dispose() | |
| $memoryStream.Dispose() | |
| return $encodedCompressedFileData | |
| } | |
| ConvertTo-CompressedBase64String -Path .\license.xml | Out-File -Encoding ascii -NoNewline -Confirm -FilePath .\secrets\sitecore-license.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment