├── .gitignore ├── .readthedocs.yaml ├── Convert.build.ps1 ├── LICENSE ├── README.md ├── buildspec_linux.yml ├── buildspec_windows.yml ├── configure_aws_credential.ps1 ├── docs ├── CHANGELOG.md ├── functions │ ├── Convert.md │ ├── ConvertFrom-Base64.md │ ├── ConvertFrom-Base64ToByteArray.md │ ├── ConvertFrom-Base64ToMemoryStream.md │ ├── ConvertFrom-Base64ToString.md │ ├── ConvertFrom-ByteArrayToBase64.md │ ├── ConvertFrom-ByteArrayToMemoryStream.md │ ├── ConvertFrom-Clixml.md │ ├── ConvertFrom-CompressedByteArrayToString.md │ ├── ConvertFrom-EscapedUrl.md │ ├── ConvertFrom-HashTable.md │ ├── ConvertFrom-MemoryStream.md │ ├── ConvertFrom-MemoryStreamToBase64.md │ ├── ConvertFrom-MemoryStreamToByteArray.md │ ├── ConvertFrom-MemoryStreamToSecureString.md │ ├── ConvertFrom-MemoryStreamToString.md │ ├── ConvertFrom-StringToBase64.md │ ├── ConvertFrom-StringToByteArray.md │ ├── ConvertFrom-StringToCompressedByteArray.md │ ├── ConvertFrom-StringToMemoryStream.md │ ├── ConvertFrom-UnixTime.md │ ├── ConvertTo-Base64.md │ ├── ConvertTo-Celsius.md │ ├── ConvertTo-Clixml.md │ ├── ConvertTo-EscapedUrl.md │ ├── ConvertTo-Fahrenheit.md │ ├── ConvertTo-Hash.md │ ├── ConvertTo-MemoryStream.md │ ├── ConvertTo-String.md │ ├── ConvertTo-TitleCase.md │ ├── ConvertTo-UnixTime.md │ └── Get-UnixTime.md ├── index.md └── requirements.txt ├── install_modules.ps1 ├── install_nuget.ps1 ├── mkdocs.yml ├── publish.ps1 └── src ├── Convert ├── Convert.psd1 ├── Convert.psm1 ├── Public │ ├── ConvertFrom-Base64.ps1 │ ├── ConvertFrom-Base64ToByteArray.ps1 │ ├── ConvertFrom-Base64ToMemoryStream.ps1 │ ├── ConvertFrom-Base64ToString.ps1 │ ├── ConvertFrom-ByteArrayToBase64.ps1 │ ├── ConvertFrom-ByteArrayToMemoryStream.ps1 │ ├── ConvertFrom-Clixml.ps1 │ ├── ConvertFrom-CompressedByteArrayToString.ps1 │ ├── ConvertFrom-EscapedUrl.ps1 │ ├── ConvertFrom-HashTable.ps1 │ ├── ConvertFrom-MemoryStream.ps1 │ ├── ConvertFrom-MemoryStreamToBase64.ps1 │ ├── ConvertFrom-MemoryStreamToByteArray.ps1 │ ├── ConvertFrom-MemoryStreamToSecureString.ps1 │ ├── ConvertFrom-MemoryStreamToString.ps1 │ ├── ConvertFrom-StringToBase64.ps1 │ ├── ConvertFrom-StringToByteArray.ps1 │ ├── ConvertFrom-StringToCompressedByteArray.ps1 │ ├── ConvertFrom-StringToMemoryStream.ps1 │ ├── ConvertFrom-UnixTime.ps1 │ ├── ConvertTo-Base64.ps1 │ ├── ConvertTo-Celsius.ps1 │ ├── ConvertTo-Clixml.ps1 │ ├── ConvertTo-EscapedUrl.ps1 │ ├── ConvertTo-Fahrenheit.ps1 │ ├── ConvertTo-Hash.ps1 │ ├── ConvertTo-MemoryStream.ps1 │ ├── ConvertTo-String.ps1 │ ├── ConvertTo-TitleCase.ps1 │ ├── ConvertTo-UnixTime.ps1 │ └── Get-UnixTime.ps1 └── _RootModule.ps1 └── Tests ├── Build └── Build.Tests.ps1 └── Unit ├── ConvertFrom-Base64.Tests.ps1 ├── ConvertFrom-Base64ToByteArray.Tests.ps1 ├── ConvertFrom-Base64ToMemoryStream.Tests.ps1 ├── ConvertFrom-Base64ToString.Tests.ps1 ├── ConvertFrom-ByteArrayToBase64.Tests.ps1 ├── ConvertFrom-ByteArrayToMemoryStream.Tests.ps1 ├── ConvertFrom-Clixml.Tests.ps1 ├── ConvertFrom-CompressedByteArrayToString.Tests.ps1 ├── ConvertFrom-EscapedUrl.Tests.ps1 ├── ConvertFrom-HashTable.Tests.ps1 ├── ConvertFrom-MemoryStream.Tests.ps1 ├── ConvertFrom-MemoryStreamToBase64.Tests.ps1 ├── ConvertFrom-MemoryStreamToSecureString.Tests.ps1 ├── ConvertFrom-MemoryStreamToString.Tests.ps1 ├── ConvertFrom-StringToBase64.Tests.ps1 ├── ConvertFrom-StringToByteArray.Tests.ps1 ├── ConvertFrom-StringToCompressedByteArray.Tests.ps1 ├── ConvertFrom-StringToMemoryStream.Tests.ps1 ├── ConvertFrom-UnixTime.Tests.ps1 ├── ConvertTo-Base64.Tests.ps1 ├── ConvertTo-Celsius.Tests.ps1 ├── ConvertTo-Clixml.Tests.ps1 ├── ConvertTo-EscapedUrl.Tests.ps1 ├── ConvertTo-Fahrenheit.Tests.ps1 ├── ConvertTo-Hash.Tests.ps1 ├── ConvertTo-MemoryStream.Tests.ps1 ├── ConvertTo-String.Tests.ps1 ├── ConvertTo-TitleCase.Tests.ps1 ├── ConvertTo-UnixTime.Tests.ps1 ├── Get-UnixTime.Tests.ps1 └── Global.Tests.ps1 /.gitignore: -------------------------------------------------------------------------------- 1 | Archive 2 | Artifacts 3 | DeploymentArtifacts 4 | .DS_Store 5 | .vscode 6 | coverage.xml 7 | test_report.xml 8 | test_report_build.xml -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # https://docs.readthedocs.io/en/stable/config-file/index.html 2 | 3 | # .readthedocs.yaml 4 | # Read the Docs configuration file 5 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 6 | 7 | # Required 8 | version: 2 9 | 10 | build: 11 | os: ubuntu-22.04 12 | tools: 13 | python: "3.11" 14 | 15 | mkdocs: 16 | configuration: mkdocs.yml 17 | 18 | python: 19 | install: 20 | - requirements: docs/requirements.txt 21 | 22 | # # Build PDF & ePub 23 | formats: all 24 | # - epub 25 | # - pdf 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Andrew Pearce 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Convert 2 | 3 | [![Minimum Supported PowerShell Version][powershell-minimum]][powershell-github] 4 | [![PowerShell Gallery][psgallery-img]][psgallery-site] 5 | 6 | [powershell-minimum]: https://img.shields.io/badge/PowerShell-5.1+-blue.svg 7 | [powershell-github]: https://github.com/PowerShell/PowerShell 8 | [psgallery-img]: https://img.shields.io/powershellgallery/dt/Convert.svg 9 | [psgallery-site]: https://www.powershellgallery.com/packages/Convert 10 | 11 | Branch | CodeBuild (Windows) | CodeBuild (Linux) | Read the Docs | 12 | --- | --- | --- | --- | 13 | master | ![Build Status][cb-m-windows] | ![Build Status][cb-m-linux] | [![rtd-image][]][rtd-site] | 14 | development | ![Build Status][cb-d-windows] | ![Build Status][cb-d-linux] | --- | 15 | 16 | [cb-m-windows]: https://codebuild.us-west-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoidFJnVXpTYzFvTEJwdWlmbmIyRmduRktWSVVCeldLQzJqYURuOUpYV0tkK2w1eS9KQXJ4K2Y5TWd4VFF1R1RJOWE2S0JXLzZ3MmhLMEV6R083NTAwUTk0PSIsIml2UGFyYW1ldGVyU3BlYyI6IjE1eVJ6bkcrOFhtUk04aFIiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master 17 | [cb-m-linux]: https://codebuild.us-west-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiRTN4QUhPbkdFWTZnSEcvNXRhQ21CU0grbVZJcFNKMktUZnhieUNPZkM5ay9ZYVhlU09MbVZWRXdySlM3M21nczFqemd6Tmt2OXg0SW9oRTZHTUpsaS9FPSIsIml2UGFyYW1ldGVyU3BlYyI6IjFPWWRaSWpENlZjQVZRbEsiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master 18 | [cb-d-windows]: https://codebuild.us-west-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoidFJnVXpTYzFvTEJwdWlmbmIyRmduRktWSVVCeldLQzJqYURuOUpYV0tkK2w1eS9KQXJ4K2Y5TWd4VFF1R1RJOWE2S0JXLzZ3MmhLMEV6R083NTAwUTk0PSIsIml2UGFyYW1ldGVyU3BlYyI6IjE1eVJ6bkcrOFhtUk04aFIiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=development 19 | [cb-d-linux]: https://codebuild.us-west-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiRTN4QUhPbkdFWTZnSEcvNXRhQ21CU0grbVZJcFNKMktUZnhieUNPZkM5ay9ZYVhlU09MbVZWRXdySlM3M21nczFqemd6Tmt2OXg0SW9oRTZHTUpsaS9FPSIsIml2UGFyYW1ldGVyU3BlYyI6IjFPWWRaSWpENlZjQVZRbEsiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=development 20 | 21 | [rtd-image]: https://readthedocs.org/projects/convert/badge/?version=latest 22 | [rtd-site]: https://readthedocs.org/projects/convert/ 23 | 24 | ## Synopsis 25 | 26 | Convert is a PowerShell Module that simplifies object conversions by exposing common requirements as standard PowerShell Functions. For example, this module includes functions for converting to and from Base64 encoded strings, MemoryStream objects, or Clixml output. 27 | 28 | ## Documentation 29 | 30 | Documentation Site: [convert.readthedocs.io](https://convert.readthedocs.io/) 31 | -------------------------------------------------------------------------------- /buildspec_linux.yml: -------------------------------------------------------------------------------- 1 | version: 0.2 2 | 3 | phases: 4 | 5 | install: 6 | runtime-versions: 7 | dotnet: 6.x 8 | 9 | commands: 10 | - export PATH="$PATH:/root/.dotnet/tools" 11 | - dotnet tool install PowerShell --global --version 7.2.8 12 | 13 | pre_build: 14 | commands: 15 | - pwsh -command '$PSVersionTable' 16 | - pwsh -command './configure_aws_credential.ps1' 17 | - pwsh -command './install_nuget.ps1' 18 | - pwsh -command './install_modules.ps1' 19 | 20 | build: 21 | commands: 22 | - pwsh -command 'Invoke-Build' 23 | 24 | artifacts: 25 | files: 26 | - '**/*' 27 | base-directory: 'DeploymentArtifacts' 28 | 29 | reports: 30 | UnitTests: 31 | files: 32 | - 'test_report.xml' 33 | discard-paths: yes 34 | file-format: JUNITXML 35 | PostBuildTests: 36 | files: 37 | - 'test_report_build.xml' 38 | discard-paths: yes 39 | file-format: JUNITXML -------------------------------------------------------------------------------- /buildspec_windows.yml: -------------------------------------------------------------------------------- 1 | version: 0.2 2 | 3 | phases: 4 | 5 | pre_build: 6 | commands: 7 | - powershell -file '.\configure_aws_credential.ps1' 8 | 9 | # Install for Windows PowerShell 10 | - powershell -command '$PSVersionTable' 11 | - powershell -file '.\install_nuget.ps1' 12 | - powershell -file '.\install_modules.ps1' 13 | 14 | # Install for PowerShell 15 | - '& "C:\Program Files\PowerShell\7\pwsh.exe" -command ''$PSVersionTable''' 16 | - '& "C:\Program Files\PowerShell\7\pwsh.exe" -file ''.\install_nuget.ps1''' 17 | - '& "C:\Program Files\PowerShell\7\pwsh.exe" -file ''.\install_modules.ps1''' 18 | 19 | build: 20 | commands: 21 | - powershell -command 'Invoke-Build' 22 | - '& "C:\Program Files\PowerShell\7\pwsh.exe" -command ''Invoke-Build''' 23 | 24 | artifacts: 25 | files: 26 | - '**/*' 27 | base-directory: 'DeploymentArtifacts' 28 | 29 | reports: 30 | UnitTests: 31 | files: 32 | - 'test_report.xml' 33 | discard-paths: yes 34 | file-format: JUNITXML -------------------------------------------------------------------------------- /configure_aws_credential.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | This script is used in AWS CodeBuild to configure the default AWS 4 | Credentials for use by the AWS CLI and the AWS Powershell module. 5 | 6 | By default, the AWS PowerShell Module does not know about looking up 7 | an AWS Container's credentials path, so this works around that issue. 8 | #> 9 | 'Configuring AWS credentials' 10 | 11 | ' - Retrieving temporary credentials from metadata' 12 | $uri = 'http://169.254.170.2{0}' -f $env:AWS_CONTAINER_CREDENTIALS_RELATIVE_URI 13 | $sts = Invoke-RestMethod -UseBasicParsing -Uri $uri 14 | 15 | ' - Setting default AWS Credential' 16 | $sb = [System.Text.StringBuilder]::new() 17 | $null = $sb.AppendLine('[default]') 18 | $null = $sb.AppendLine('aws_access_key_id={0}' -f $sts.AccessKeyId) 19 | $null = $sb.AppendLine('aws_secret_access_key={0}' -f $sts.SecretAccessKey) 20 | $null = $sb.AppendLine('aws_session_token={0}' -f $sts.Token) 21 | 22 | ' - Setting default AWS Region' 23 | $null = $sb.AppendLine('region={0}' -f $env:AWS_DEFAULT_REGION) 24 | 25 | $credentialsFile = "$env:HOME\.aws\credentials" 26 | $null = New-Item -Path $credentialsFile -Force 27 | $sb.ToString() | Out-File -FilePath $credentialsFile -Append 28 | 29 | ' - AWS credentials configured' 30 | -------------------------------------------------------------------------------- /docs/functions/Convert.md: -------------------------------------------------------------------------------- 1 | --- 2 | Module Name: Convert 3 | Module Guid: d87140ad-7077-477a-b517-758954215e87 4 | Download Help Link: NA 5 | Help Version: 1.5.0 6 | Locale: en-US 7 | --- 8 | 9 | # Convert Module 10 | 11 | ## Description 12 | 13 | Convert simplifies object conversions by exposing common requirements as PowerShell functions. 14 | 15 | ## Convert Cmdlets 16 | 17 | ### [ConvertFrom-Base64](ConvertFrom-Base64.md) 18 | 19 | Converts a base64 encoded string to a string. 20 | 21 | ### [ConvertFrom-Base64ToByteArray](ConvertFrom-Base64ToByteArray.md) 22 | 23 | Converts a Base 64 Encoded String to a Byte Array 24 | 25 | ### [ConvertFrom-Base64ToMemoryStream](ConvertFrom-Base64ToMemoryStream.md) 26 | 27 | Converts a base64 encoded string to a MemoryStream. 28 | 29 | ### [ConvertFrom-Base64ToString](ConvertFrom-Base64ToString.md) 30 | 31 | Converts a base64 encoded string to a string. 32 | 33 | ### [ConvertFrom-ByteArrayToBase64](ConvertFrom-ByteArrayToBase64.md) 34 | 35 | Converts a byte array to a base64 encoded string. 36 | 37 | ### [ConvertFrom-ByteArrayToMemoryStream](ConvertFrom-ByteArrayToMemoryStream.md) 38 | 39 | Converts a Byte Array to a MemoryStream 40 | 41 | ### [ConvertFrom-Clixml](ConvertFrom-Clixml.md) 42 | 43 | Converts Clixml to an object. 44 | 45 | ### [ConvertFrom-CompressedByteArrayToString](ConvertFrom-CompressedByteArrayToString.md) 46 | 47 | Converts a string to a byte array object. 48 | 49 | ### [ConvertFrom-EscapedUrl](ConvertFrom-EscapedUrl.md) 50 | 51 | Converts an escaped URL back to a standard Url. 52 | 53 | ### [ConvertFrom-HashTable](ConvertFrom-HashTable.md) 54 | 55 | Converts HashTable objects to PSCustomObject objects. 56 | 57 | ### [ConvertFrom-MemoryStream](ConvertFrom-MemoryStream.md) 58 | 59 | Converts MemoryStream to a base64 encoded string. 60 | 61 | ### [ConvertFrom-MemoryStreamToBase64](ConvertFrom-MemoryStreamToBase64.md) 62 | 63 | Converts MemoryStream to a base64 encoded string. 64 | 65 | ### [ConvertFrom-MemoryStreamToByteArray](ConvertFrom-MemoryStreamToByteArray.md) 66 | 67 | Converts MemoryStream to a byte array. 68 | 69 | ### [ConvertFrom-MemoryStreamToSecureString](ConvertFrom-MemoryStreamToSecureString.md) 70 | 71 | Converts a Memory Stream to a Secure String 72 | 73 | ### [ConvertFrom-MemoryStreamToString](ConvertFrom-MemoryStreamToString.md) 74 | 75 | Converts MemoryStream to a string. 76 | 77 | ### [ConvertFrom-StringToBase64](ConvertFrom-StringToBase64.md) 78 | 79 | Converts a string to a base64 encoded string. 80 | 81 | ### [ConvertFrom-StringToByteArray](ConvertFrom-StringToByteArray.md) 82 | 83 | Converts a string to a byte array object. 84 | 85 | ### [ConvertFrom-StringToCompressedByteArray](ConvertFrom-StringToCompressedByteArray.md) 86 | 87 | Converts a string to a compressed byte array object. 88 | 89 | ### [ConvertFrom-StringToMemoryStream](ConvertFrom-StringToMemoryStream.md) 90 | 91 | Converts a string to a MemoryStream object. 92 | 93 | ### [ConvertFrom-UnixTime](ConvertFrom-UnixTime.md) 94 | 95 | Converts a date time represented in Unix time to a PowerShell DateTime object. 96 | 97 | ### [ConvertTo-Base64](ConvertTo-Base64.md) 98 | 99 | Converts a string to a base64 encoded string. 100 | 101 | ### [ConvertTo-Celsius](ConvertTo-Celsius.md) 102 | Converts a temperature from Fahrenheit to Celsius. 103 | 104 | ### [ConvertTo-Clixml](ConvertTo-Clixml.md) 105 | 106 | Converts an object to Clixml. 107 | 108 | ### [ConvertTo-EscapedUrl](ConvertTo-EscapedUrl.md) 109 | 110 | Converts a URL to an escaped Url. 111 | 112 | ### [ConvertTo-Fahrenheit](ConvertTo-Fahrenheit.md) 113 | Converts a temperature from Celsius to Fahrenheit. 114 | 115 | ### [ConvertTo-Hash](ConvertTo-Hash.md) 116 | 117 | Converts a string to a hash. 118 | 119 | ### [ConvertTo-MemoryStream](ConvertTo-MemoryStream.md) 120 | 121 | Converts an object to a MemoryStream object. 122 | 123 | ### [ConvertTo-String](ConvertTo-String.md) 124 | 125 | Converts a base64 encoded string to a string. 126 | 127 | ### [ConvertTo-TitleCase](ConvertTo-TitleCase.md) 128 | 129 | Convert a string to title case. 130 | 131 | ### [ConvertTo-UnixTime](ConvertTo-UnixTime.md) 132 | 133 | Converts a date time to the date time represented in Unix time. 134 | 135 | ### [Get-UnixTime](Get-UnixTime.md) 136 | 137 | Gets the current date time represented in Unix time. 138 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-Base64.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-Base64 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a base64 encoded string to a string. 13 | 14 | ## SYNTAX 15 | 16 | ### Default (Default) 17 | 18 | ```powershell 19 | ConvertFrom-Base64 -Base64 [-ToString] [-Decompress] [] 20 | ``` 21 | 22 | ### ToString 23 | 24 | ```powershell 25 | ConvertFrom-Base64 -Base64 [-Encoding ] [-ToString] [-Decompress] [] 26 | ``` 27 | 28 | ## DESCRIPTION 29 | 30 | Converts a base64 encoded string to a string. 31 | 32 | ## EXAMPLES 33 | 34 | ### EXAMPLE 1 35 | 36 | ```powershell 37 | ConvertFrom-Base64 -Base64 'QSBzdHJpbmc=' -ToString 38 | ``` 39 | 40 | A string 41 | 42 | ### EXAMPLE 2 43 | 44 | ```powershell 45 | ConvertTo-Base64 -Base64 'A string','Another string' -ToString 46 | 47 | QSBzdHJpbmc= 48 | QW5vdGhlciBzdHJpbmc= 49 | ``` 50 | 51 | ### EXAMPLE 3 52 | 53 | ```powershell 54 | 'QSBzdHJpbmc=' | ConvertFrom-Base64 -ToString 55 | 56 | A string 57 | ``` 58 | 59 | ### EXAMPLE 4 60 | 61 | ```powershell 62 | 'QSBzdHJpbmc=','QW5vdGhlciBzdHJpbmc=' | ConvertFrom-Base64 -ToString 63 | 64 | A string 65 | Another string 66 | ``` 67 | 68 | ## PARAMETERS 69 | 70 | ### -Base64 71 | 72 | A Base64 Encoded String. 73 | 74 | ```yaml 75 | Type: String[] 76 | Parameter Sets: (All) 77 | Aliases: String, Base64String 78 | 79 | Required: True 80 | Position: Named 81 | Default value: None 82 | Accept pipeline input: True (ByPropertyName, ByValue) 83 | Accept wildcard characters: False 84 | ``` 85 | 86 | ### -Encoding 87 | 88 | The encoding to use for conversion. 89 | Defaults to UTF8. 90 | Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, and UTF8. 91 | 92 | ```yaml 93 | Type: String 94 | Parameter Sets: ToString 95 | Aliases: 96 | 97 | Required: False 98 | Position: Named 99 | Default value: UTF8 100 | Accept pipeline input: False 101 | Accept wildcard characters: False 102 | ``` 103 | 104 | ### -ToString 105 | 106 | Switch parameter to specify a conversion to a string object. 107 | 108 | ```yaml 109 | Type: SwitchParameter 110 | Parameter Sets: (All) 111 | Aliases: 112 | 113 | Required: False 114 | Position: Named 115 | Default value: False 116 | Accept pipeline input: False 117 | Accept wildcard characters: False 118 | ``` 119 | 120 | ### -Decompress 121 | 122 | If supplied, the output will be decompressed using Gzip. 123 | 124 | ```yaml 125 | Type: SwitchParameter 126 | Parameter Sets: (All) 127 | Aliases: 128 | 129 | Required: False 130 | Position: Named 131 | Default value: False 132 | Accept pipeline input: False 133 | Accept wildcard characters: False 134 | ``` 135 | 136 | ### CommonParameters 137 | 138 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 139 | 140 | ## INPUTS 141 | 142 | ## OUTPUTS 143 | 144 | ### [String[]] 145 | 146 | ## NOTES 147 | 148 | ## RELATED LINKS 149 | 150 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64/) 151 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-Base64ToByteArray.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: https://msdn.microsoft.com/en-us/library/system.convert.frombase64string%28v=vs.110%29.aspx 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-Base64ToByteArray 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a Base 64 Encoded String to a Byte Array 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-Base64ToByteArray [-String] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts a Base 64 Encoded String to a Byte Array 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | ConvertFrom-Base64ToByteArray -String 'dGVzdA==' 30 | 116 31 | 101 32 | 115 33 | 116 34 | ``` 35 | 36 | Converts the base64 string to its byte array representation. 37 | 38 | ## PARAMETERS 39 | 40 | ### -String 41 | 42 | The Base 64 Encoded String to be converted 43 | 44 | ```yaml 45 | Type: String 46 | Parameter Sets: (All) 47 | Aliases: Base64String 48 | 49 | Required: True 50 | Position: 1 51 | Default value: None 52 | Accept pipeline input: False 53 | Accept wildcard characters: False 54 | ``` 55 | 56 | ### CommonParameters 57 | 58 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 59 | 60 | ## INPUTS 61 | 62 | ## OUTPUTS 63 | 64 | ## NOTES 65 | 66 | ## RELATED LINKS 67 | 68 | [https://msdn.microsoft.com/en-us/library/system.convert.frombase64string%28v=vs.110%29.aspx](https://msdn.microsoft.com/en-us/library/system.convert.frombase64string%28v=vs.110%29.aspx) 69 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-Base64ToMemoryStream.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64ToMemoryStream/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-Base64ToMemoryStream 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a base64 encoded string to a MemoryStream. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-Base64ToMemoryStream [-String] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts a base64 encoded string to a MemoryStream. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | ConvertFrom-Base64ToMemoryStream -String 'QSBzdHJpbmc=' 30 | ``` 31 | 32 | ### EXAMPLE 2 33 | 34 | ```powershell 35 | ConvertFrom-Base64ToMemoryStream -String 'A string','Another string' 36 | ``` 37 | 38 | ### EXAMPLE 3 39 | 40 | ```powershell 41 | 'QSBzdHJpbmc=' | ConvertFrom-Base64ToMemoryStream 42 | ``` 43 | 44 | ### EXAMPLE 4 45 | 46 | ```powershell 47 | 'QSBzdHJpbmc=','QW5vdGhlciBzdHJpbmc=' | ConvertFrom-Base64ToMemoryStream 48 | ``` 49 | 50 | ## PARAMETERS 51 | 52 | ### -String 53 | 54 | A Base64 Encoded String 55 | 56 | ```yaml 57 | Type: String[] 58 | Parameter Sets: (All) 59 | Aliases: Base64String 60 | 61 | Required: True 62 | Position: 1 63 | Default value: None 64 | Accept pipeline input: True (ByPropertyName, ByValue) 65 | Accept wildcard characters: False 66 | ``` 67 | 68 | ### CommonParameters 69 | 70 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 71 | 72 | ## INPUTS 73 | 74 | ## OUTPUTS 75 | 76 | ### [String[]] 77 | 78 | ## NOTES 79 | 80 | ## RELATED LINKS 81 | 82 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64ToMemoryStream/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64ToMemoryStream/) 83 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-Base64ToString.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64ToString/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-Base64ToString 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a base64 encoded string to a string. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-Base64ToString [-String] [[-Encoding] ] [-Decompress] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts a base64 encoded string to a string. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | ConvertFrom-Base64ToString -String 'QSBzdHJpbmc=' 30 | 31 | A string 32 | ``` 33 | 34 | ### EXAMPLE 2 35 | 36 | ```powershell 37 | ConvertTo-Base64 -String 'A string','Another string' 38 | 39 | QSBzdHJpbmc= 40 | QW5vdGhlciBzdHJpbmc= 41 | ``` 42 | 43 | ### EXAMPLE 3 44 | 45 | ```powershell 46 | 'QSBzdHJpbmc=' | ConvertFrom-Base64ToString 47 | 48 | A string 49 | ``` 50 | 51 | ### EXAMPLE 4 52 | 53 | ```powershell 54 | 'QSBzdHJpbmc=','QW5vdGhlciBzdHJpbmc=' | ConvertFrom-Base64ToString 55 | 56 | A string 57 | Another string 58 | ``` 59 | 60 | ## PARAMETERS 61 | 62 | ### -String 63 | 64 | A Base64 Encoded String 65 | 66 | ```yaml 67 | Type: String[] 68 | Parameter Sets: (All) 69 | Aliases: Base64String 70 | 71 | Required: True 72 | Position: 1 73 | Default value: None 74 | Accept pipeline input: True (ByPropertyName, ByValue) 75 | Accept wildcard characters: False 76 | ``` 77 | 78 | ### -Encoding 79 | 80 | The encoding to use for conversion. 81 | Defaults to UTF8. 82 | Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, and UTF8. 83 | 84 | ```yaml 85 | Type: String 86 | Parameter Sets: (All) 87 | Aliases: 88 | 89 | Required: False 90 | Position: 2 91 | Default value: UTF8 92 | Accept pipeline input: False 93 | Accept wildcard characters: False 94 | ``` 95 | 96 | ### -Decompress 97 | 98 | If supplied, the output will be decompressed using Gzip. 99 | 100 | ```yaml 101 | Type: SwitchParameter 102 | Parameter Sets: (All) 103 | Aliases: 104 | 105 | Required: False 106 | Position: Named 107 | Default value: False 108 | Accept pipeline input: False 109 | Accept wildcard characters: False 110 | ``` 111 | 112 | ### CommonParameters 113 | 114 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 115 | 116 | ## INPUTS 117 | 118 | ## OUTPUTS 119 | 120 | ### [String[]] 121 | 122 | ## NOTES 123 | 124 | ## RELATED LINKS 125 | 126 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64ToString/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64ToString/) 127 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-ByteArrayToBase64.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-ByteArrayToBase64/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-ByteArrayToBase64 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a byte array to a base64 encoded string. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-ByteArrayToBase64 [-ByteArray] [-Compress] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts a byte array to a base64 encoded string. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | $bytes = ConvertFrom-StringToCompressedByteArray -String 'A string' 30 | ConvertFrom-ByteArrayToBase64 -ByteArray $bytes 31 | 32 | H4sIAAAAAAAAC3NUKC4pysxLBwCMN9RgCAAAAA== 33 | ``` 34 | 35 | ## PARAMETERS 36 | 37 | ### -ByteArray 38 | 39 | A byte array object for conversion. 40 | 41 | ```yaml 42 | Type: Byte[] 43 | Parameter Sets: (All) 44 | Aliases: Bytes 45 | 46 | Required: True 47 | Position: 1 48 | Default value: None 49 | Accept pipeline input: True (ByPropertyName, ByValue) 50 | Accept wildcard characters: False 51 | ``` 52 | 53 | ### -Compress 54 | 55 | If supplied, the output will be compressed using Gzip. 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: Named 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### CommonParameters 70 | 71 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 72 | 73 | ## INPUTS 74 | 75 | ## OUTPUTS 76 | 77 | ### [String[]] 78 | 79 | ## NOTES 80 | 81 | ## RELATED LINKS 82 | 83 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-ByteArrayToBase64/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-ByteArrayToBase64/) 84 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-ByteArrayToMemoryStream.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: https://msdn.microsoft.com/en-us/library/system.io.memorystream(v=vs.110).aspx 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-ByteArrayToMemoryStream 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a Byte Array to a MemoryStream 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-ByteArrayToMemoryStream [-ByteArray] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts a Byte Array to a MemoryStream 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | ConvertFrom-ByteArrayToMemoryStream -ByteArray ([Byte[]] (,0xFF * 100)) 30 | ``` 31 | 32 | This command uses the ConvertFrom-ByteArrayToMemoryStream cmdlet to convert a Byte Array into a Memory Stream. 33 | 34 | ## PARAMETERS 35 | 36 | ### -ByteArray 37 | 38 | The Byte Array to be converted 39 | 40 | ```yaml 41 | Type: Byte[] 42 | Parameter Sets: (All) 43 | Aliases: Bytes 44 | 45 | Required: True 46 | Position: 1 47 | Default value: None 48 | Accept pipeline input: False 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### CommonParameters 53 | 54 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 55 | 56 | ## INPUTS 57 | 58 | ## OUTPUTS 59 | 60 | ## NOTES 61 | 62 | Additional information: 63 | https://msdn.microsoft.com/en-us/library/63z365ty(v=vs.110).aspx 64 | 65 | ## RELATED LINKS 66 | 67 | [https://msdn.microsoft.com/en-us/library/system.io.memorystream(v=vs.110).aspx](https://msdn.microsoft.com/en-us/library/system.io.memorystream(v=vs.110).aspx) 68 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-Clixml.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Clixml/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-Clixml 9 | 10 | ## SYNOPSIS 11 | 12 | Converts Clixml to an object. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-Clixml [-String] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts Clixml to an object. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | $xml = @" 30 | 31 | ThisIsMyString 32 | 33 | "@ 34 | ConvertFrom-Clixml -String $xml 35 | 36 | ThisIsMyString 37 | ``` 38 | 39 | ### EXAMPLE 2 40 | 41 | ```powershell 42 | $xml = @" 43 | 44 | ThisIsMyString 45 | 46 | "@ 47 | $xml | ConvertFrom-Clixml 48 | 49 | ThisIsMyString 50 | ``` 51 | 52 | ### EXAMPLE 3 53 | 54 | ```powershell 55 | $xml = @" 56 | 57 | ThisIsMyString 58 | 59 | "@ 60 | $xml2 = @" 61 | 62 | This is another string 63 | 64 | "@ 65 | ConvertFrom-Clixml -String $xml,$xml2 66 | 67 | ThisIsMyString 68 | This is another string 69 | ``` 70 | 71 | ### EXAMPLE 4 72 | 73 | ```powershell 74 | $xml = @" 75 | 76 | ThisIsMyString 77 | 78 | "@ 79 | $xml2 = @" 80 | 81 | This is another string 82 | 83 | "@ 84 | $xml,$xml2 | ConvertFrom-Clixml 85 | 86 | ThisIsMyString 87 | This is another string 88 | ``` 89 | 90 | ## PARAMETERS 91 | 92 | ### -String 93 | 94 | Clixml as a string object. 95 | 96 | ```yaml 97 | Type: String[] 98 | Parameter Sets: (All) 99 | Aliases: 100 | 101 | Required: True 102 | Position: 1 103 | Default value: None 104 | Accept pipeline input: True (ByPropertyName, ByValue) 105 | Accept wildcard characters: False 106 | ``` 107 | 108 | ### CommonParameters 109 | 110 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 111 | 112 | ## INPUTS 113 | 114 | ## OUTPUTS 115 | 116 | ### [Object[]] 117 | 118 | ## NOTES 119 | 120 | ## RELATED LINKS 121 | 122 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Clixml/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Clixml/) 123 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-CompressedByteArrayToString.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-CompressedByteArrayToString/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-CompressedByteArrayToString 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a string to a byte array object. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-CompressedByteArrayToString [-ByteArray] [[-Encoding] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts a string to a byte array object. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | $bytes = ConvertFrom-CompressedByteArrayToString -String 'A string' 30 | $bytes.GetType() 31 | 32 | IsPublic IsSerial Name BaseType 33 | -------- -------- ---- -------- 34 | True True Object\[\] System.Array 35 | 36 | $bytes\[0\].GetType() 37 | 38 | IsPublic IsSerial Name BaseType 39 | -------- -------- ---- -------- 40 | True True Byte System.ValueType 41 | ``` 42 | 43 | ## PARAMETERS 44 | 45 | ### -ByteArray 46 | 47 | The array of bytes to convert. 48 | 49 | ```yaml 50 | Type: Byte[] 51 | Parameter Sets: (All) 52 | Aliases: 53 | 54 | Required: True 55 | Position: 1 56 | Default value: None 57 | Accept pipeline input: True (ByPropertyName, ByValue) 58 | Accept wildcard characters: False 59 | ``` 60 | 61 | ### -Encoding 62 | 63 | The encoding to use for conversion. 64 | Defaults to UTF8. 65 | Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, and UTF8. 66 | 67 | ```yaml 68 | Type: String 69 | Parameter Sets: (All) 70 | Aliases: 71 | 72 | Required: False 73 | Position: 2 74 | Default value: UTF8 75 | Accept pipeline input: False 76 | Accept wildcard characters: False 77 | ``` 78 | 79 | ### CommonParameters 80 | 81 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 82 | 83 | ## INPUTS 84 | 85 | ## OUTPUTS 86 | 87 | ### [Byte[]] 88 | 89 | ## NOTES 90 | 91 | ## RELATED LINKS 92 | 93 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-CompressedByteArrayToString/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-CompressedByteArrayToString/) 94 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-EscapedUrl.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-EscapedUrl/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-EscapedUrl 9 | 10 | ## SYNOPSIS 11 | 12 | Converts an escaped URL back to a standard Url. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-EscapedUrl [[-Url] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts an escaped URL back to a standard Url. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | ConvertFrom-EscapedUrl -Url 'http%3A%2F%2Ftest.com%3Fvalue%3Dmy%20value' 30 | ``` 31 | 32 | Returns the string `http://test.com?value=my value`. 33 | 34 | ## PARAMETERS 35 | 36 | ### -Url 37 | 38 | The escaped URL to convert. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: False 46 | Position: 1 47 | Default value: None 48 | Accept pipeline input: True (ByPropertyName, ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### CommonParameters 53 | 54 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 55 | 56 | ## INPUTS 57 | 58 | ## OUTPUTS 59 | 60 | ### [string] 61 | 62 | ## NOTES 63 | 64 | ## RELATED LINKS 65 | 66 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-EscapedUrl/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-EscapedUrl/) 67 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-HashTable.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-HashTable/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-HashTable 9 | 10 | ## SYNOPSIS 11 | 12 | Converts HashTable objects to PSCustomObject objects. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-HashTable [[-HashTable] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts HashTable objects to PSCustomObject objects. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | ConvertFrom-HashTable -HashTable @{'foo'='bar'} 30 | ``` 31 | 32 | Returns a PSCustomObject with the property 'foo' with value 'bar'. 33 | 34 | ### EXAMPLE 2 35 | 36 | ```powershell 37 | @{'foo'='bar'} | ConvertFrom-HashTable 38 | ``` 39 | 40 | Returns a PSCustomObject with the property 'foo' with value 'bar'. 41 | 42 | ## PARAMETERS 43 | 44 | ### -HashTable 45 | 46 | A list of HashTable objects to convert 47 | 48 | ```yaml 49 | Type: Hashtable[] 50 | Parameter Sets: (All) 51 | Aliases: 52 | 53 | Required: False 54 | Position: 1 55 | Default value: None 56 | Accept pipeline input: True (ByPropertyName, ByValue) 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### CommonParameters 61 | 62 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 63 | 64 | ## INPUTS 65 | 66 | ## OUTPUTS 67 | 68 | ### [PSCustomObject[]] 69 | 70 | ## NOTES 71 | 72 | ## RELATED LINKS 73 | 74 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-HashTable/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-HashTable/) 75 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-MemoryStreamToBase64.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToBase64/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-MemoryStreamToBase64 9 | 10 | ## SYNOPSIS\ 11 | 12 | Converts MemoryStream to a base64 encoded string. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-MemoryStreamToBase64 [-MemoryStream] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts MemoryStream to a base64 encoded string. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | $string = 'A string' 30 | $stream = [System.IO.MemoryStream]::new() 31 | $writer = [System.IO.StreamWriter]::new($stream) 32 | $writer.Write($string) 33 | $writer.Flush() 34 | 35 | ConvertFrom-MemoryStreamToBase64 -MemoryStream $stream 36 | 37 | QSBzdHJpbmc= 38 | ``` 39 | 40 | ### EXAMPLE 2 41 | 42 | ```powershell 43 | $string = 'A string' 44 | $stream = [System.IO.MemoryStream]::new() 45 | $writer = [System.IO.StreamWriter]::new($stream) 46 | $writer.Write($string) 47 | $writer.Flush() 48 | 49 | $stream | ConvertFrom-MemoryStreamToBase64 50 | 51 | QSBzdHJpbmc= 52 | ``` 53 | 54 | ### EXAMPLE 3 55 | 56 | ```powershell 57 | $string1 = 'A string' 58 | $stream1 = [System.IO.MemoryStream]::new() 59 | $writer1 = [System.IO.StreamWriter]::new($stream1) 60 | $writer1.Write($string1) 61 | $writer1.Flush() 62 | 63 | $string2 = 'Another string' 64 | $stream2 = \[System.IO.MemoryStream\]::new() 65 | $writer2 = \[System.IO.StreamWriter\]::new($stream2) 66 | $writer2.Write($string2) 67 | $writer2.Flush() 68 | 69 | ConvertFrom-MemoryStreamToBase64 -MemoryStream $stream1,$stream2 70 | 71 | QSBzdHJpbmc= 72 | QW5vdGhlciBzdHJpbmc= 73 | ``` 74 | 75 | ### EXAMPLE 4 76 | 77 | ```powershell 78 | $string1 = 'A string' 79 | $stream1 = [System.IO.MemoryStream]::new() 80 | $writer1 = [System.IO.StreamWriter]::new($stream1) 81 | $writer1.Write($string1) 82 | $writer1.Flush() 83 | 84 | $string2 = 'Another string' 85 | $stream2 = \[System.IO.MemoryStream\]::new() 86 | $writer2 = \[System.IO.StreamWriter\]::new($stream2) 87 | $writer2.Write($string2) 88 | $writer2.Flush() 89 | 90 | $stream1,$stream2 | ConvertFrom-MemoryStreamToBase64 91 | 92 | QSBzdHJpbmc= 93 | QW5vdGhlciBzdHJpbmc= 94 | ``` 95 | 96 | ## PARAMETERS 97 | 98 | ### -MemoryStream 99 | 100 | A MemoryStream object for conversion. 101 | 102 | ```yaml 103 | Type: MemoryStream[] 104 | Parameter Sets: (All) 105 | Aliases: 106 | 107 | Required: True 108 | Position: 1 109 | Default value: None 110 | Accept pipeline input: True (ByPropertyName, ByValue) 111 | Accept wildcard characters: False 112 | ``` 113 | 114 | ### CommonParameters 115 | 116 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 117 | 118 | ## INPUTS 119 | 120 | ## OUTPUTS 121 | 122 | ### [String[]] 123 | 124 | ## NOTES 125 | 126 | ## RELATED LINKS 127 | 128 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToBase64/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToBase64/) 129 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-MemoryStreamToByteArray.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToByteArray/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-MemoryStreamToByteArray 9 | 10 | ## SYNOPSIS 11 | 12 | Converts MemoryStream to a byte array. 13 | 14 | ## SYNTAX 15 | 16 | ### MemoryStream 17 | 18 | ```powershell 19 | ConvertFrom-MemoryStreamToByteArray -MemoryStream [] 20 | ``` 21 | 22 | ### Stream 23 | 24 | ```powershell 25 | ConvertFrom-MemoryStreamToByteArray -Stream [] 26 | ``` 27 | 28 | ## DESCRIPTION 29 | 30 | Converts MemoryStream to a byte array. 31 | 32 | ## EXAMPLES 33 | 34 | ### EXAMPLE 1 35 | 36 | ```powershell 37 | $string = 'A string' 38 | $stream = [System.IO.MemoryStream]::new() 39 | $writer = [System.IO.StreamWriter]::new($stream) 40 | $writer.Write($string) 41 | $writer.Flush() 42 | 43 | ConvertFrom-MemoryStreamToByteArray -MemoryStream $stream 44 | ``` 45 | 46 | ### EXAMPLE 2 47 | 48 | ```powershell 49 | $string = 'A string' 50 | $stream = [System.IO.MemoryStream]::new() 51 | $writer = [System.IO.StreamWriter]::new($stream) 52 | $writer.Write($string) 53 | $writer.Flush() 54 | 55 | $stream | ConvertFrom-MemoryStreamToByteArray 56 | ``` 57 | 58 | ### EXAMPLE 3 59 | 60 | ```powershell 61 | $string1 = 'A string' 62 | $stream1 = [System.IO.MemoryStream]::new() 63 | $writer1 = [System.IO.StreamWriter]::new($stream1) 64 | $writer1.Write($string1) 65 | $writer1.Flush() 66 | 67 | $string2 = 'Another string' 68 | $stream2 = \[System.IO.MemoryStream\]::new() 69 | $writer2 = \[System.IO.StreamWriter\]::new($stream2) 70 | $writer2.Write($string2) 71 | $writer2.Flush() 72 | 73 | ConvertFrom-MemoryStreamToByteArray -MemoryStream $stream1,$stream2 74 | ``` 75 | 76 | ### EXAMPLE 4 77 | 78 | ```powershell 79 | $string1 = 'A string' 80 | $stream1 = [System.IO.MemoryStream]::new() 81 | $writer1 = [System.IO.StreamWriter]::new($stream1) 82 | $writer1.Write($string1) 83 | $writer1.Flush() 84 | 85 | $string2 = 'Another string' 86 | $stream2 = \[System.IO.MemoryStream\]::new() 87 | $writer2 = \[System.IO.StreamWriter\]::new($stream2) 88 | $writer2.Write($string2) 89 | $writer2.Flush() 90 | 91 | $stream1,$stream2 | ConvertFrom-MemoryStreamToByteArray 92 | ``` 93 | 94 | ## PARAMETERS 95 | 96 | ### -MemoryStream 97 | 98 | A System.IO.MemoryStream object for conversion. 99 | 100 | ```yaml 101 | Type: MemoryStream[] 102 | Parameter Sets: MemoryStream 103 | Aliases: 104 | 105 | Required: True 106 | Position: Named 107 | Default value: None 108 | Accept pipeline input: True (ByPropertyName, ByValue) 109 | Accept wildcard characters: False 110 | ``` 111 | 112 | ### -Stream 113 | 114 | A System.IO.Stream object for conversion. 115 | 116 | ```yaml 117 | Type: Stream[] 118 | Parameter Sets: Stream 119 | Aliases: 120 | 121 | Required: True 122 | Position: Named 123 | Default value: None 124 | Accept pipeline input: True (ByPropertyName) 125 | Accept wildcard characters: False 126 | ``` 127 | 128 | ### CommonParameters 129 | 130 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 131 | 132 | ## INPUTS 133 | 134 | ## OUTPUTS 135 | 136 | ### [String[]] 137 | 138 | ## NOTES 139 | 140 | ## RELATED LINKS 141 | 142 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToByteArray/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToByteArray/) 143 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-MemoryStreamToSecureString.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: https://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-MemoryStreamToSecureString 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a Memory Stream to a Secure String 13 | 14 | ## SYNTAX 15 | 16 | ### MemoryStream (Default) 17 | 18 | ```powershell 19 | ConvertFrom-MemoryStreamToSecureString -MemoryStream [] 20 | ``` 21 | 22 | ### Stream 23 | 24 | ```powershell 25 | ConvertFrom-MemoryStreamToSecureString -Stream [] 26 | ``` 27 | 28 | ## DESCRIPTION 29 | 30 | This cmdlet converts a Memory Stream to a Secure String using a Stream Reader object. 31 | 32 | ## EXAMPLES 33 | 34 | ### EXAMPLE 1 35 | 36 | ```powershell 37 | $string = 'My Super Secret Value' 38 | $bytes = [System.Text.Encoding]::UTF8.GetBytes($string) 39 | $memoryStream = [System.IO.MemoryStream]::new($bytes, 0, $bytes.Length) 40 | $secure = ConvertFrom-MemoryStreamToSecureString -MemoryStream $memoryStream 41 | $credential = [PSCredential]::new('MyValue', $secure) 42 | 43 | Converts the provided MemoryStream to a SeureString. 44 | ``` 45 | 46 | ## PARAMETERS 47 | 48 | ### -MemoryStream 49 | 50 | A System.IO.MemoryStream object for conversion. 51 | 52 | ```yaml 53 | Type: MemoryStream[] 54 | Parameter Sets: MemoryStream 55 | Aliases: 56 | 57 | Required: True 58 | Position: Named 59 | Default value: None 60 | Accept pipeline input: True (ByPropertyName, ByValue) 61 | Accept wildcard characters: False 62 | ``` 63 | 64 | ### -Stream 65 | 66 | A System.IO.Stream object for conversion. 67 | 68 | ```yaml 69 | Type: Stream[] 70 | Parameter Sets: Stream 71 | Aliases: 72 | 73 | Required: True 74 | Position: Named 75 | Default value: None 76 | Accept pipeline input: True (ByPropertyName) 77 | Accept wildcard characters: False 78 | ``` 79 | 80 | ### CommonParameters 81 | 82 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 83 | 84 | ## INPUTS 85 | 86 | ## OUTPUTS 87 | 88 | ## NOTES 89 | 90 | Additional information: 91 | https://msdn.microsoft.com/en-us/library/system.io.streamreader%28v=vs.110%29.aspx 92 | https://msdn.microsoft.com/en-us/library/system.security.securestring%28v=vs.110%29.aspx 93 | 94 | ## RELATED LINKS 95 | 96 | [https://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx](https://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx) 97 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-MemoryStreamToString.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToString/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-MemoryStreamToString 9 | 10 | ## SYNOPSIS 11 | 12 | Converts MemoryStream to a string. 13 | 14 | ## SYNTAX 15 | 16 | ### MemoryStream 17 | 18 | ```powershell 19 | ConvertFrom-MemoryStreamToString -MemoryStream [] 20 | ``` 21 | 22 | ### Stream 23 | 24 | ```powershell 25 | ConvertFrom-MemoryStreamToString -Stream [] 26 | ``` 27 | 28 | ## DESCRIPTION 29 | 30 | Converts MemoryStream to a string. 31 | 32 | ## EXAMPLES 33 | 34 | ### EXAMPLE 1 35 | 36 | ```powershell 37 | $string = 'A string' 38 | $stream = [System.IO.MemoryStream]::new() 39 | $writer = [System.IO.StreamWriter]::new($stream) 40 | $writer.Write($string) 41 | $writer.Flush() 42 | 43 | ConvertFrom-MemoryStreamToString -MemoryStream $stream 44 | 45 | A string 46 | ``` 47 | 48 | ### EXAMPLE 2 49 | 50 | ```powershell 51 | $string = 'A string' 52 | $stream = [System.IO.MemoryStream]::new() 53 | $writer = [System.IO.StreamWriter]::new($stream) 54 | $writer.Write($string) 55 | $writer.Flush() 56 | 57 | $stream | ConvertFrom-MemoryStreamToString 58 | 59 | A string 60 | ``` 61 | 62 | ### EXAMPLE 3 63 | 64 | ```powershell 65 | $string1 = 'A string' 66 | $stream1 = [System.IO.MemoryStream]::new() 67 | $writer1 = [System.IO.StreamWriter]::new($stream1) 68 | $writer1.Write($string1) 69 | $writer1.Flush() 70 | 71 | $string2 = 'Another string' 72 | $stream2 = \[System.IO.MemoryStream\]::new() 73 | $writer2 = \[System.IO.StreamWriter\]::new($stream2) 74 | $writer2.Write($string2) 75 | $writer2.Flush() 76 | 77 | ConvertFrom-MemoryStreamToString -MemoryStream $stream1,$stream2 78 | 79 | A string 80 | Another string 81 | ``` 82 | 83 | ### EXAMPLE 4 84 | 85 | ```powershell 86 | $string1 = 'A string' 87 | $stream1 = [System.IO.MemoryStream]::new() 88 | $writer1 = [System.IO.StreamWriter]::new($stream1) 89 | $writer1.Write($string1) 90 | $writer1.Flush() 91 | 92 | $string2 = 'Another string' 93 | $stream2 = \[System.IO.MemoryStream\]::new() 94 | $writer2 = \[System.IO.StreamWriter\]::new($stream2) 95 | $writer2.Write($string2) 96 | $writer2.Flush() 97 | 98 | $stream1,$stream2 | ConvertFrom-MemoryStreamToString 99 | 100 | A string 101 | Another string 102 | ``` 103 | 104 | ## PARAMETERS 105 | 106 | ### -MemoryStream 107 | 108 | A System.IO.MemoryStream object for conversion. 109 | 110 | ```yaml 111 | Type: MemoryStream[] 112 | Parameter Sets: MemoryStream 113 | Aliases: 114 | 115 | Required: True 116 | Position: Named 117 | Default value: None 118 | Accept pipeline input: True (ByPropertyName, ByValue) 119 | Accept wildcard characters: False 120 | ``` 121 | 122 | ### -Stream 123 | 124 | A System.IO.Stream object for conversion. 125 | 126 | ```yaml 127 | Type: Stream[] 128 | Parameter Sets: Stream 129 | Aliases: 130 | 131 | Required: True 132 | Position: Named 133 | Default value: None 134 | Accept pipeline input: True (ByPropertyName) 135 | Accept wildcard characters: False 136 | ``` 137 | 138 | ### CommonParameters 139 | 140 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 141 | 142 | ## INPUTS 143 | 144 | ## OUTPUTS 145 | 146 | ### [String[]] 147 | 148 | ## NOTES 149 | 150 | ## RELATED LINKS 151 | 152 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToString/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToString/) 153 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-StringToBase64.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToBase64/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-StringToBase64 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a string to a base64 encoded string. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-StringToBase64 [-String] [[-Encoding] ] [-Compress] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts a string to a base64 encoded string. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | ConvertFrom-StringToBase64 -String 'A string' 30 | 31 | QSBzdHJpbmc= 32 | ``` 33 | 34 | ### EXAMPLE 2 35 | 36 | ```powershell 37 | 'A string' | ConvertFrom-StringToBase64 38 | 39 | QSBzdHJpbmc= 40 | ``` 41 | 42 | ### EXAMPLE 3 43 | 44 | ```powershell 45 | ConvertFrom-StringToBase64 -String 'A string' -Encoding Unicode 46 | 47 | QQAgAHMAdAByAGkAbgBnAA== 48 | ``` 49 | 50 | ### EXAMPLE 4 51 | 52 | ```powershell 53 | 'A string' | ConvertFrom-StringToBase64 -Encoding Unicode 54 | 55 | QQAgAHMAdAByAGkAbgBnAA== 56 | ``` 57 | 58 | ### EXAMPLE 5 59 | 60 | ```powershell 61 | ConvertFrom-StringToBase64 -String 'A string','Another string' 62 | 63 | QSBzdHJpbmc= 64 | QW5vdGhlciBzdHJpbmc= 65 | ``` 66 | 67 | ### EXAMPLE 6 68 | 69 | ```powershell 70 | 'A string','Another string' | ConvertFrom-StringToBase64 71 | 72 | QSBzdHJpbmc= 73 | QW5vdGhlciBzdHJpbmc= 74 | ``` 75 | 76 | ### EXAMPLE 7 77 | 78 | ```powershell 79 | ConvertFrom-StringToBase64 -String 'A string','Another string' -Encoding Unicode 80 | 81 | QQAgAHMAdAByAGkAbgBnAA== 82 | QQBuAG8AdABoAGUAcgAgAHMAdAByAGkAbgBnAA== 83 | ``` 84 | 85 | ### EXAMPLE 8 86 | 87 | ```powershell 88 | 'A string','Another string' | ConvertFrom-StringToBase64 -Encoding Unicode 89 | 90 | QQAgAHMAdAByAGkAbgBnAA== 91 | QQBuAG8AdABoAGUAcgAgAHMAdAByAGkAbgBnAA== 92 | ``` 93 | 94 | ## PARAMETERS 95 | 96 | ### -String 97 | 98 | A string object for conversion. 99 | 100 | ```yaml 101 | Type: String[] 102 | Parameter Sets: (All) 103 | Aliases: 104 | 105 | Required: True 106 | Position: 1 107 | Default value: None 108 | Accept pipeline input: True (ByPropertyName, ByValue) 109 | Accept wildcard characters: False 110 | ``` 111 | 112 | ### -Encoding 113 | 114 | The encoding to use for conversion. 115 | Defaults to UTF8. 116 | Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, and UTF8. 117 | 118 | ```yaml 119 | Type: String 120 | Parameter Sets: (All) 121 | Aliases: 122 | 123 | Required: False 124 | Position: 2 125 | Default value: UTF8 126 | Accept pipeline input: False 127 | Accept wildcard characters: False 128 | ``` 129 | 130 | ### -Compress 131 | 132 | If supplied, the output will be compressed using Gzip. 133 | 134 | ```yaml 135 | Type: SwitchParameter 136 | Parameter Sets: (All) 137 | Aliases: 138 | 139 | Required: False 140 | Position: Named 141 | Default value: False 142 | Accept pipeline input: False 143 | Accept wildcard characters: False 144 | ``` 145 | 146 | ### CommonParameters 147 | 148 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 149 | 150 | ## INPUTS 151 | 152 | ## OUTPUTS 153 | 154 | ### [String[]] 155 | 156 | ## NOTES 157 | 158 | ## RELATED LINKS 159 | 160 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToBase64/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToBase64/) 161 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-StringToByteArray.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToByteArray/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-StringToByteArray 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a string to a byte array object. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-StringToByteArray [-String] [[-Encoding] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts a string to a byte array object. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | $bytes = ConvertFrom-StringToByteArray -String 'A string' 30 | $bytes.GetType() 31 | 32 | IsPublic IsSerial Name BaseType 33 | -------- -------- ---- -------- 34 | True True Byte\[\] System.Array 35 | 36 | $bytes\[0\].GetType() 37 | 38 | IsPublic IsSerial Name BaseType 39 | -------- -------- ---- -------- 40 | True True Byte System.ValueType 41 | ``` 42 | 43 | ### EXAMPLE 2 44 | 45 | ```powershell 46 | $bytes = 'A string','Another string' | ConvertFrom-StringToByteArray 47 | 48 | $bytes.Count 49 | 2 50 | 51 | $bytes.GetType() 52 | 53 | IsPublic IsSerial Name BaseType 54 | -------- -------- ---- -------- 55 | True True Object\[\] System.Array 56 | 57 | $bytes\[0\].GetType() 58 | 59 | IsPublic IsSerial Name BaseType 60 | -------- -------- ---- -------- 61 | True True Byte\[\] System.Array 62 | ``` 63 | 64 | ## PARAMETERS 65 | 66 | ### -String 67 | 68 | A string object for conversion. 69 | 70 | ```yaml 71 | Type: String[] 72 | Parameter Sets: (All) 73 | Aliases: 74 | 75 | Required: True 76 | Position: 1 77 | Default value: None 78 | Accept pipeline input: True (ByPropertyName, ByValue) 79 | Accept wildcard characters: False 80 | ``` 81 | 82 | ### -Encoding 83 | 84 | The encoding to use for conversion. 85 | Defaults to UTF8. 86 | Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, and UTF8. 87 | 88 | ```yaml 89 | Type: String 90 | Parameter Sets: (All) 91 | Aliases: 92 | 93 | Required: False 94 | Position: 2 95 | Default value: UTF8 96 | Accept pipeline input: False 97 | Accept wildcard characters: False 98 | ``` 99 | 100 | ### CommonParameters 101 | 102 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 103 | 104 | ## INPUTS 105 | 106 | ## OUTPUTS 107 | 108 | ### [System.Collections.Generic.List[Byte[]]] 109 | 110 | ## NOTES 111 | 112 | ## RELATED LINKS 113 | 114 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToByteArray/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToByteArray/) 115 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-StringToCompressedByteArray.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToCompressedByteArray/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-StringToCompressedByteArray 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a string to a compressed byte array object. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-StringToCompressedByteArray [-String] [[-Encoding] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts a string to a compressed byte array object. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | $bytes = ConvertFrom-StringToCompressedByteArray -String 'A string' 30 | $bytes.GetType() 31 | 32 | IsPublic IsSerial Name BaseType 33 | -------- -------- ---- -------- 34 | True True Byte\[\] System.Array 35 | 36 | $bytes\[0\].GetType() 37 | 38 | IsPublic IsSerial Name BaseType 39 | -------- -------- ---- -------- 40 | True True Byte System.ValueType 41 | ``` 42 | 43 | ## PARAMETERS 44 | 45 | ### -String 46 | 47 | A string object for conversion. 48 | 49 | ```yaml 50 | Type: String[] 51 | Parameter Sets: (All) 52 | Aliases: 53 | 54 | Required: True 55 | Position: 1 56 | Default value: None 57 | Accept pipeline input: True (ByPropertyName, ByValue) 58 | Accept wildcard characters: False 59 | ``` 60 | 61 | ### -Encoding 62 | 63 | The encoding to use for conversion. 64 | Defaults to UTF8. 65 | Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, and UTF8. 66 | 67 | ```yaml 68 | Type: String 69 | Parameter Sets: (All) 70 | Aliases: 71 | 72 | Required: False 73 | Position: 2 74 | Default value: UTF8 75 | Accept pipeline input: False 76 | Accept wildcard characters: False 77 | ``` 78 | 79 | ### CommonParameters 80 | 81 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 82 | 83 | ## INPUTS 84 | 85 | ## OUTPUTS 86 | 87 | ### [System.Collections.Generic.List[Byte[]]] 88 | 89 | ## NOTES 90 | 91 | ## RELATED LINKS 92 | 93 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToCompressedByteArray/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToCompressedByteArray/) 94 | -------------------------------------------------------------------------------- /docs/functions/ConvertFrom-UnixTime.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertFrom-UnixTime/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertFrom-UnixTime 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a date time represented in Unix time to a PowerShell DateTime object. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertFrom-UnixTime [[-UnixTime] ] [-FromMilliseconds] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts a date time represented in Unix time to a PowerShell DateTime object. 23 | 24 | Supports Unix time in seconds by default, or a switch to support Unix time in milliseconds. 25 | 26 | ## EXAMPLES 27 | 28 | ### EXAMPLE 1 29 | 30 | ```powershell 31 | ConvertFrom-UnixTime -UnixTime 1674712047 32 | 33 | Thursday, January 26, 2023 5:47:27 AM 34 | ``` 35 | 36 | ### EXAMPLE 2 37 | 38 | ```powershell 39 | 1674712047 | ConvertFrom-UnixTime 40 | 41 | Thursday, January 26, 2023 5:47:27 AM 42 | ``` 43 | 44 | ### EXAMPLE 3 45 | 46 | ```powershell 47 | ConvertFrom-UnixTime -UnixTime 1674712048705 -FromMilliseconds 48 | 49 | Thursday, January 26, 2023 5:47:28 AM 50 | ``` 51 | 52 | ### EXAMPLE 4 53 | 54 | ```powershell 55 | 1674712048705 | ConvertFrom-UnixTime -FromMilliseconds 56 | 57 | Thursday, January 26, 2023 5:47:28 AM 58 | ``` 59 | 60 | ## PARAMETERS 61 | 62 | ### -UnixTime 63 | 64 | The Unix time to convert. 65 | Represented in seconds by default, or in milliseconds if the FromMilliseconds 66 | parameter is specified. 67 | 68 | ```yaml 69 | Type: Int64 70 | Parameter Sets: (All) 71 | Aliases: 72 | 73 | Required: False 74 | Position: 1 75 | Default value: 0 76 | Accept pipeline input: True (ByPropertyName, ByValue) 77 | Accept wildcard characters: False 78 | ``` 79 | 80 | ### -FromMilliseconds 81 | 82 | If specified, returns the time in milliseconds that have elapsed since 00:00:00 UTC on 1 January, 1970. 83 | 84 | ```yaml 85 | Type: SwitchParameter 86 | Parameter Sets: (All) 87 | Aliases: 88 | 89 | Required: False 90 | Position: Named 91 | Default value: False 92 | Accept pipeline input: False 93 | Accept wildcard characters: False 94 | ``` 95 | 96 | ### CommonParameters 97 | 98 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 99 | 100 | ## INPUTS 101 | 102 | ## OUTPUTS 103 | 104 | ### [datetime] 105 | 106 | ## NOTES 107 | 108 | ## RELATED LINKS 109 | 110 | [http://convert.readthedocs.io/en/latest/functions/ConvertFrom-UnixTime/](http://convert.readthedocs.io/en/latest/functions/ConvertFrom-UnixTime/) 111 | -------------------------------------------------------------------------------- /docs/functions/ConvertTo-Celsius.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertTo-Fahrenheit/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertTo-Celsius 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a temperature from Fahrenheit to Celsius. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertTo-Celsius [-Fahrenheit] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | The ConvertTo-Celsius function converts a temperature value from Fahrenheit to Celsius. 23 | It accepts input via parameter or pipeline, validates that the temperature is not below absolute zero 24 | (-459.67°F), and returns the result rounded to two decimal places. 25 | 26 | ## EXAMPLES 27 | 28 | ### EXAMPLE 1 29 | ```powershell 30 | ConvertTo-Celsius -Fahrenheit 32 31 | 0 32 | ``` 33 | 34 | Converts 32°F to Celsius (0°C). 35 | 36 | ### EXAMPLE 2 37 | 38 | ```powershell 39 | ConvertTo-Celsius -Fahrenheit 98.6 40 | 37 41 | ``` 42 | 43 | Converts normal body temperature (98.6°F) to Celsius (37°C). 44 | 45 | ### EXAMPLE 3 46 | 47 | ```powershell 48 | 212 | ConvertTo-Celsius 49 | 100 50 | ``` 51 | 52 | Demonstrates pipeline input, converting 212°F to Celsius (100°C). 53 | 54 | ### EXAMPLE 4 55 | 56 | ```powershell 57 | ConvertTo-Celsius -Fahrenheit -40 58 | -40 59 | ``` 60 | 61 | Converts -40°F to Celsius (-40°C), demonstrating the point where both scales intersect. 62 | 63 | ## PARAMETERS 64 | 65 | ### -Fahrenheit 66 | 67 | The temperature in Fahrenheit to convert. 68 | Must be greater than or equal to -459.67°F (absolute zero). 69 | This parameter accepts pipeline input. 70 | 71 | ```yaml 72 | Type: Double 73 | Parameter Sets: (All) 74 | Aliases: 75 | 76 | Required: True 77 | Position: 1 78 | Default value: 0 79 | Accept pipeline input: True (ByValue) 80 | Accept wildcard characters: False 81 | ``` 82 | 83 | ### CommonParameters 84 | 85 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 86 | 87 | ## INPUTS 88 | 89 | ### System.Double 90 | 91 | ### You can pipe a double value representing the temperature in Fahrenheit to this function. 92 | 93 | ## OUTPUTS 94 | 95 | ### System.Double 96 | 97 | ### Returns the temperature in Celsius as a double value, rounded to two decimal places. 98 | 99 | ## NOTES 100 | 101 | The formula used is: °C = (°F - 32) × 5/9 102 | 103 | ## RELATED LINKS 104 | 105 | [http://convert.readthedocs.io/en/latest/functions/ConvertTo-Fahrenheit/](http://convert.readthedocs.io/en/latest/functions/ConvertTo-Fahrenheit/) 106 | [https://en.wikipedia.org/wiki/Celsius](https://en.wikipedia.org/wiki/Celsius) 107 | -------------------------------------------------------------------------------- /docs/functions/ConvertTo-Clixml.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertTo-Clixml/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertTo-Clixml 9 | 10 | ## SYNOPSIS 11 | 12 | Converts an object to Clixml. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertTo-Clixml [-InputObject] [[-Depth] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts an object to Clixml. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | $string = 'A string' 30 | ConvertTo-Clixml -InputObject $string 31 | 32 | \ 33 | \A string\ 34 | \ 35 | ``` 36 | 37 | ### EXAMPLE 2 38 | 39 | ```powershell 40 | $string = 'A string' 41 | $string | ConvertTo-Clixml 42 | 43 | \ 44 | \A string\ 45 | \ 46 | ``` 47 | 48 | ### EXAMPLE 3 49 | 50 | ```powershell 51 | $string1 = 'A string' 52 | $string2 = 'Another string' 53 | ConvertTo-Clixml -InputObject $string1,$string2 54 | 55 | \ 56 | \A string\ 57 | \ 58 | \ 59 | \Another string\ 60 | \ 61 | ``` 62 | 63 | ### EXAMPLE 4 64 | 65 | ```powershell 66 | $string1 = 'A string' 67 | $string2 = 'Another string' 68 | $string1,$string2 | ConvertTo-Clixml 69 | 70 | \ 71 | \A string\ 72 | \ 73 | \ 74 | \Another string\ 75 | \ 76 | ``` 77 | 78 | ## PARAMETERS 79 | 80 | ### -InputObject 81 | 82 | The input object to serialize 83 | 84 | ```yaml 85 | Type: PSObject 86 | Parameter Sets: (All) 87 | Aliases: 88 | 89 | Required: True 90 | Position: 1 91 | Default value: None 92 | Accept pipeline input: True (ByPropertyName, ByValue) 93 | Accept wildcard characters: False 94 | ``` 95 | 96 | ### -Depth 97 | 98 | The depth of the members to serialize 99 | 100 | ```yaml 101 | Type: Int32 102 | Parameter Sets: (All) 103 | Aliases: 104 | 105 | Required: False 106 | Position: 2 107 | Default value: 1 108 | Accept pipeline input: False 109 | Accept wildcard characters: False 110 | ``` 111 | 112 | ### CommonParameters 113 | 114 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 115 | 116 | ## INPUTS 117 | 118 | ## OUTPUTS 119 | 120 | ### [String[]] 121 | 122 | ## NOTES 123 | 124 | ## RELATED LINKS 125 | 126 | [http://convert.readthedocs.io/en/latest/functions/ConvertTo-Clixml/](http://convert.readthedocs.io/en/latest/functions/ConvertTo-Clixml/) 127 | -------------------------------------------------------------------------------- /docs/functions/ConvertTo-EscapedUrl.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertTo-Clixml/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertTo-EscapedUrl 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a URL to an escaped Url. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertTo-EscapedUrl [[-Url] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts a URL to an escaped Url. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | ConvertTo-EscapedUrl -Url 'http://test.com?value=my value' 30 | ``` 31 | 32 | Returns the string \`http%3A%2F%2Ftest.com%3Fvalue%3Dmy%20value\`. 33 | 34 | ## PARAMETERS 35 | 36 | ### -Url 37 | 38 | The URL to escape. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: False 46 | Position: 1 47 | Default value: None 48 | Accept pipeline input: True (ByPropertyName, ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### CommonParameters 53 | 54 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 55 | 56 | ## INPUTS 57 | 58 | ## OUTPUTS 59 | 60 | ### [string] 61 | 62 | ## NOTES 63 | 64 | ## RELATED LINKS 65 | -------------------------------------------------------------------------------- /docs/functions/ConvertTo-Fahrenheit.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertTo-Fahrenheit 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a temperature from Celsius to Fahrenheit. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertTo-Fahrenheit [-Celsius] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | The ConvertTo-Fahrenheit function converts a temperature value from Celsius to Fahrenheit. 23 | It accepts input via parameter or pipeline, validates that the temperature is not below absolute zero 24 | (-273.15°C), and returns the result rounded to two decimal places. 25 | 26 | ## EXAMPLES 27 | 28 | ### EXAMPLE 1 29 | 30 | ```powershell 31 | ConvertTo-Fahrenheit -Celsius 0 32 | 32 33 | ``` 34 | 35 | Converts 0°C to Fahrenheit (32°F). 36 | 37 | ### EXAMPLE 2 38 | 39 | ```powershell 40 | ConvertTo-Fahrenheit -Celsius 37 41 | 98.6 42 | ``` 43 | 44 | Converts body temperature (37°C) to Fahrenheit (98.6°F). 45 | 46 | ### EXAMPLE 3 47 | 48 | ```powershell 49 | 100 | ConvertTo-Fahrenheit 50 | 212 51 | ``` 52 | 53 | Demonstrates pipeline input, converting 100°C to Fahrenheit (212°F). 54 | 55 | ### EXAMPLE 4 56 | 57 | ```powershell 58 | ConvertTo-Fahrenheit -Celsius -40 59 | -40 60 | ``` 61 | 62 | Converts -40°C to Fahrenheit (-40°F), demonstrating the point where both scales intersect. 63 | 64 | ## PARAMETERS 65 | 66 | ### -Celsius 67 | The temperature in Celsius to convert. 68 | Must be greater than or equal to -273.15°C (absolute zero). 69 | This parameter accepts pipeline input. 70 | 71 | ```yaml 72 | Type: Double 73 | Parameter Sets: (All) 74 | Aliases: 75 | 76 | Required: True 77 | Position: 1 78 | Default value: 0 79 | Accept pipeline input: True (ByValue) 80 | Accept wildcard characters: False 81 | ``` 82 | 83 | ### CommonParameters 84 | 85 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 86 | 87 | ## INPUTS 88 | 89 | ### System.Double 90 | 91 | ### You can pipe a double value representing the temperature in Celsius to this function. 92 | 93 | ## OUTPUTS 94 | 95 | ### System.Double 96 | 97 | ### Returns the temperature in Fahrenheit as a double value, rounded to two decimal places. 98 | 99 | ## NOTES 100 | 101 | The formula used is: °F = (°C × 9/5) + 32 102 | 103 | ## RELATED LINKS 104 | 105 | [http://convert.readthedocs.io/en/latest/functions/ConvertTo-Celsius/](http://convert.readthedocs.io/en/latest/functions/ConvertTo-Celsius/) 106 | [https://en.wikipedia.org/wiki/Fahrenheit](https://en.wikipedia.org/wiki/Fahrenheit) 107 | -------------------------------------------------------------------------------- /docs/functions/ConvertTo-Hash.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertTo-Hash/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertTo-Hash 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a string to a hash. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertTo-Hash [-String ] [-Algorithm ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts a string to a hash. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | ConvertTo-Hash -String 'MyString' 30 | 38F92FF0761E08356B7C51C5A1ED88602882C2768F37C2DCC3F0AC6EE3F950F5 31 | ``` 32 | 33 | ## PARAMETERS 34 | 35 | ### -String 36 | 37 | A string to convert. 38 | 39 | ```yaml 40 | Type: String 41 | Parameter Sets: (All) 42 | Aliases: 43 | 44 | Required: False 45 | Position: Named 46 | Default value: None 47 | Accept pipeline input: True (ByPropertyName, ByValue) 48 | Accept wildcard characters: False 49 | ``` 50 | 51 | ### -Algorithm 52 | 53 | The hashing algorithm to use. 54 | Defaults to 'SHA256'. 55 | 56 | ```yaml 57 | Type: String 58 | Parameter Sets: (All) 59 | Aliases: 60 | 61 | Required: False 62 | Position: Named 63 | Default value: SHA256 64 | Accept pipeline input: False 65 | Accept wildcard characters: False 66 | ``` 67 | 68 | ### CommonParameters 69 | 70 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 71 | 72 | ## INPUTS 73 | 74 | ## OUTPUTS 75 | 76 | ### [String[]] 77 | 78 | ## NOTES 79 | 80 | ## RELATED LINKS 81 | 82 | [http://convert.readthedocs.io/en/latest/functions/ConvertTo-Hash/](http://convert.readthedocs.io/en/latest/functions/ConvertTo-Hash/) 83 | -------------------------------------------------------------------------------- /docs/functions/ConvertTo-MemoryStream.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertTo-MemoryStream/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertTo-MemoryStream 9 | 10 | ## SYNOPSIS 11 | 12 | Converts an object to a MemoryStream object. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertTo-MemoryStream -String [-Encoding ] [-Compress] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts an object to a MemoryStream object. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | $string = 'A string' 30 | $stream = ConvertTo-MemoryStream -String $string 31 | $stream.GetType() 32 | 33 | IsPublic IsSerial Name BaseType 34 | -------- -------- ---- -------- 35 | True True MemoryStream System.IO.Stream 36 | ``` 37 | 38 | ### EXAMPLE 2 39 | 40 | ```powershell 41 | $string = 'A string' 42 | $stream = $string | ConvertTo-MemoryStream 43 | $stream.GetType() 44 | 45 | IsPublic IsSerial Name BaseType 46 | -------- -------- ---- -------- 47 | True True MemoryStream System.IO.Stream 48 | ``` 49 | 50 | ### EXAMPLE 3 51 | 52 | ```powershell 53 | $string1 = 'A string' 54 | $string2 = 'Another string' 55 | 56 | $streams = ConvertTo-MemoryStream -String $string1,$string2 57 | $streams.GetType() 58 | 59 | IsPublic IsSerial Name BaseType 60 | -------- -------- ---- -------- 61 | True True Object\[\] System.Array 62 | 63 | $streams\[0\].GetType() 64 | 65 | IsPublic IsSerial Name BaseType 66 | -------- -------- ---- -------- 67 | True True MemoryStream System.IO.Stream 68 | ``` 69 | 70 | ### EXAMPLE 4 71 | 72 | ```powershell 73 | $string1 = 'A string' 74 | $string2 = 'Another string' 75 | 76 | $streams = $string1,$string2 | ConvertTo-MemoryStream 77 | $streams.GetType() 78 | 79 | IsPublic IsSerial Name BaseType 80 | -------- -------- ---- -------- 81 | True True Object\[\] System.Array 82 | 83 | $streams\[0\].GetType() 84 | 85 | IsPublic IsSerial Name BaseType 86 | -------- -------- ---- -------- 87 | True True MemoryStream System.IO.Stream 88 | ``` 89 | 90 | ## PARAMETERS 91 | 92 | ### -String 93 | 94 | A string object for conversion. 95 | 96 | ```yaml 97 | Type: String[] 98 | Parameter Sets: (All) 99 | Aliases: 100 | 101 | Required: True 102 | Position: Named 103 | Default value: None 104 | Accept pipeline input: True (ByPropertyName, ByValue) 105 | Accept wildcard characters: False 106 | ``` 107 | 108 | ### -Encoding 109 | 110 | The encoding to use for conversion. 111 | Defaults to UTF8. 112 | Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, and UTF8. 113 | 114 | ```yaml 115 | Type: String 116 | Parameter Sets: (All) 117 | Aliases: 118 | 119 | Required: False 120 | Position: Named 121 | Default value: UTF8 122 | Accept pipeline input: False 123 | Accept wildcard characters: False 124 | ``` 125 | 126 | ### -Compress 127 | 128 | If supplied, the output will be compressed using Gzip. 129 | 130 | ```yaml 131 | Type: SwitchParameter 132 | Parameter Sets: (All) 133 | Aliases: 134 | 135 | Required: False 136 | Position: Named 137 | Default value: False 138 | Accept pipeline input: False 139 | Accept wildcard characters: False 140 | ``` 141 | 142 | ### CommonParameters 143 | 144 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 145 | 146 | ## INPUTS 147 | 148 | ## OUTPUTS 149 | 150 | ### [System.IO.MemoryStream[]] 151 | 152 | ## NOTES 153 | 154 | ## RELATED LINKS 155 | 156 | [http://convert.readthedocs.io/en/latest/functions/ConvertTo-MemoryStream/](http://convert.readthedocs.io/en/latest/functions/ConvertTo-MemoryStream/) 157 | -------------------------------------------------------------------------------- /docs/functions/ConvertTo-TitleCase.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertTo-TitleCase/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertTo-TitleCase 9 | 10 | ## SYNOPSIS 11 | 12 | Convert a string to title case. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertTo-TitleCase [[-String] ] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Convert a string to title case. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | 28 | ```powershell 29 | ConvertTo-TitleCase -String 'my string' 30 | 31 | Returns the string \`My String\`. 32 | ``` 33 | 34 | ## PARAMETERS 35 | 36 | ### -String 37 | 38 | The string to convert. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: False 46 | Position: 1 47 | Default value: None 48 | Accept pipeline input: True (ByPropertyName, ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### CommonParameters 53 | 54 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 55 | 56 | ## INPUTS 57 | 58 | ## OUTPUTS 59 | 60 | ### [string] 61 | 62 | ## NOTES 63 | 64 | ## RELATED LINKS 65 | 66 | [http://convert.readthedocs.io/en/latest/functions/ConvertTo-TitleCase/](http://convert.readthedocs.io/en/latest/functions/ConvertTo-TitleCase/) 67 | -------------------------------------------------------------------------------- /docs/functions/ConvertTo-UnixTime.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/ConvertTo-UnixTime/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # ConvertTo-UnixTime 9 | 10 | ## SYNOPSIS 11 | 12 | Converts a date time to the date time represented in Unix time. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | ConvertTo-UnixTime [[-DateTime] ] [-AsMilliseconds] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Converts a date time to the date time represented in Unix time, which is the time in seconds that have elapsed since 23 | 00:00:00 UTC on 1 January, 1970. 24 | 25 | A switch is provided to return the time value repsented in milliseconds. 26 | 27 | ## EXAMPLES 28 | 29 | ### EXAMPLE 1 30 | 31 | ```powershell 32 | ConvertTo-UnixTime 33 | 34 | 1674712201 35 | ``` 36 | 37 | ### EXAMPLE 2 38 | 39 | ```powershell 40 | Get-Date | ConvertTo-UnixTime 41 | 42 | 1674683490 43 | ``` 44 | 45 | ### EXAMPLE 3 46 | 47 | ```powershell 48 | ConvertTo-UnixTime -DateTime (Get-Date).AddMonths(6) 49 | 50 | 1690321833 51 | ``` 52 | 53 | ### EXAMPLE 4 54 | 55 | ```powershell 56 | ConvertTo-UnixTime -AsMilliseconds 57 | 58 | 1674712253812 59 | ``` 60 | 61 | ## PARAMETERS 62 | 63 | ### -DateTime 64 | 65 | A DateTime object representing the time to convert. 66 | Defaults to \`\[datetime\]::UtcNow\`. 67 | 68 | ```yaml 69 | Type: DateTime 70 | Parameter Sets: (All) 71 | Aliases: 72 | 73 | Required: False 74 | Position: 1 75 | Default value: [datetime]::UtcNow 76 | Accept pipeline input: True (ByPropertyName, ByValue) 77 | Accept wildcard characters: False 78 | ``` 79 | 80 | ### -AsMilliseconds 81 | 82 | If specified, returns the time in milliseconds that have elapsed since 00:00:00 UTC on 1 January, 1970. 83 | 84 | ```yaml 85 | Type: SwitchParameter 86 | Parameter Sets: (All) 87 | Aliases: 88 | 89 | Required: False 90 | Position: Named 91 | Default value: False 92 | Accept pipeline input: False 93 | Accept wildcard characters: False 94 | ``` 95 | 96 | ### CommonParameters 97 | 98 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 99 | 100 | ## INPUTS 101 | 102 | ## OUTPUTS 103 | 104 | ### [long] 105 | 106 | ## NOTES 107 | 108 | ## RELATED LINKS 109 | 110 | [http://convert.readthedocs.io/en/latest/functions/ConvertTo-UnixTime/](http://convert.readthedocs.io/en/latest/functions/ConvertTo-UnixTime/) 111 | -------------------------------------------------------------------------------- /docs/functions/Get-UnixTime.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: Convert-help.xml 3 | Module Name: Convert 4 | online version: http://convert.readthedocs.io/en/latest/functions/Get-UnixTime/ 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-UnixTime 9 | 10 | ## SYNOPSIS 11 | 12 | Gets the current date time represented in Unix time. 13 | 14 | ## SYNTAX 15 | 16 | ```powershell 17 | Get-UnixTime [-AsMilliseconds] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Gets the current date time represented in Unix time, which is the time in seconds that have elapsed since 00:00:00 UTC on 23 | 1 January, 1970. 24 | 25 | A switch is provided to return the time value repsented in milliseconds. 26 | 27 | ## EXAMPLES 28 | 29 | ### EXAMPLE 1 30 | 31 | ```powershell 32 | Get-UnixTime 33 | 34 | 1674712340 35 | ``` 36 | 37 | ### EXAMPLE 2 38 | 39 | ```powershell 40 | Get-UnixTime -AsMilliseconds 41 | 42 | 1674712353731 43 | ``` 44 | 45 | ## PARAMETERS 46 | 47 | ### -AsMilliseconds 48 | 49 | If specified, returns the time in milliseconds that have elapsed since 00:00:00 UTC on 1 January, 1970. 50 | 51 | ```yaml 52 | Type: SwitchParameter 53 | Parameter Sets: (All) 54 | Aliases: 55 | 56 | Required: False 57 | Position: Named 58 | Default value: False 59 | Accept pipeline input: False 60 | Accept wildcard characters: False 61 | ``` 62 | 63 | ### CommonParameters 64 | 65 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 66 | 67 | ## INPUTS 68 | 69 | ## OUTPUTS 70 | 71 | ### [long] 72 | 73 | ## NOTES 74 | 75 | ## RELATED LINKS 76 | 77 | [http://convert.readthedocs.io/en/latest/functions/Get-UnixTime/](http://convert.readthedocs.io/en/latest/functions/Get-UnixTime/) 78 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Convert 2 | A PowerShell Module to simplify object conversions. 3 | 4 | ## What is Convert? 5 | Convert is a PowerShell Module that simplifies object conversion by exposing common actions as standard PowerShell Functions. These include common actions such as converting to and from Base64 encoded strings, MemoryStream objects, or Clixml output. 6 | 7 | ## Readme 8 | [https://github.com/austoonz/Convert/blob/master/README.md](https://github.com/austoonz/Convert/blob/master/README.md) 9 | 10 | ## ChangeLog 11 | [https://github.com/austoonz/Convert/blob/master/CHANGELOG.md](https://github.com/austoonz/Convert/blob/master/CHANGELOG.md) -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | # https://github.com/readthedocs-examples/example-mkdocs-basic/blob/main/docs/requirements.txt 2 | # requirements.txt 3 | jinja2==3.1.6 4 | mkdocs>=1.4.2 5 | -------------------------------------------------------------------------------- /install_modules.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | This script is used to install the required PowerShell Modules for the build process. 4 | It has a dependency on the PowerShell Gallery. 5 | #> 6 | $global:VerbosePreference = 'SilentlyContinue' 7 | $ErrorActionPreference = 'Stop' 8 | $ProgressPreference = 'SilentlyContinue' 9 | $VerbosePreference = 'SilentlyContinue' 10 | 11 | # Fix for PowerShell Gallery and TLS1.2 12 | # https://devblogs.microsoft.com/powershell/powershell-gallery-tls-support/ 13 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 14 | Install-Module -Name 'PowerShellGet' -MinimumVersion '2.2.4' -SkipPublisherCheck -Force -AllowClobber 15 | 16 | # Fix for build environments that include the monolithic AWS Tools for PowerShell 17 | $installedModules = Get-Module -ListAvailable 18 | $installedModules.Where({$_.Name -eq 'AWSPowerShell'}) | ForEach-Object { 19 | Remove-Item -Path $_.Path -Force -Recurse 20 | } 21 | $installedModules.Where({$_.Name -eq 'AWSPowerShell.NetCore'}) | ForEach-Object { 22 | Remove-Item -Path $_.Path -Force -Recurse 23 | } 24 | 25 | # List of PowerShell Modules required for the build 26 | $modulesToInstall = @( 27 | @{ 28 | ModuleName = 'AWS.Tools.S3' 29 | ModuleVersion = '4.1.241' 30 | } 31 | @{ 32 | ModuleName = 'InvokeBuild' 33 | ModuleVersion = '5.10.1' 34 | } 35 | @{ 36 | ModuleName = 'Pester' 37 | ModuleVersion = '5.3.3' 38 | } 39 | @{ 40 | ModuleName = 'platyPS' 41 | ModuleVersion = '0.14.2' 42 | } 43 | @{ 44 | ModuleName = 'PSScriptAnalyzer' 45 | ModuleVersion = '1.21.0' 46 | } 47 | ) 48 | 49 | $installModule = @{ 50 | Scope = 'CurrentUser' 51 | AllowClobber = $true 52 | Force = $true 53 | SkipPublisherCheck = $true 54 | Verbose = $false 55 | } 56 | 57 | $installedModules = Get-Module -ListAvailable 58 | 59 | foreach ($module in $modulesToInstall) { 60 | Write-Host (' - {0} {1}' -f $module.ModuleName, $module.ModuleVersion) 61 | 62 | if ($module.ModuleName -like 'AWS.Tools.*' -and $installedModules.Where( { $_.Name -like 'AWSPowerShell*' } )) { 63 | Write-Host ' A legacy AWS PowerShell module is installed. Skipping...' 64 | continue 65 | } 66 | 67 | if ($installedModules.Where( { $_.Name -eq $module.ModuleName -and $_.Version -eq $module.ModuleVersion } )) { 68 | Write-Host (' Already installed. Skipping...' -f $module.ModuleName) 69 | continue 70 | } 71 | 72 | Install-Module -Name $module.ModuleName -RequiredVersion $module.ModuleVersion @installModule 73 | Import-Module -Name $module.ModuleName -Force 74 | } 75 | 76 | Get-Module -ListAvailable | Select-Object -Property Name,Version | Sort-Object -Property Name | Format-Table -------------------------------------------------------------------------------- /install_nuget.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | This script is used to ensure the NuGet provider is installed. 4 | #> 5 | $global:VerbosePreference = 'SilentlyContinue' 6 | $ErrorActionPreference = 'Stop' 7 | $ProgressPreference = 'SilentlyContinue' 8 | $VerbosePreference = 'SilentlyContinue' 9 | 10 | # Fix for PowerShell Gallery and TLS1.2 11 | # https://devblogs.microsoft.com/powershell/powershell-gallery-tls-support/ 12 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 13 | $installPackageProvider = @{ 14 | Name = 'NuGet' 15 | MinimumVersion = '2.8.5.201' 16 | Scope = 'CurrentUser' 17 | Confirm = $false 18 | Force = $true 19 | ErrorAction = 'SilentlyContinue' 20 | } 21 | $null = Install-PackageProvider @installPackageProvider 22 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: Convert - PowerShell Module for object conversions 2 | site_description: Convert is a PowerShell module that simplifies object conversions by exposing common requirements as PowerShell functions. # meta tag to the generated HTML header 3 | repo_url: https://github.com/austoonz/Convert 4 | site_author: Andrew Pearce 5 | edit_uri: edit/master/docs/ 6 | theme: readthedocs 7 | copyright: "Convert is licensed under the MIT license" 8 | nav: 9 | - Home: index.md 10 | - Change Log: CHANGELOG.md 11 | - Functions: 12 | - ConvertFrom-Base64: functions/ConvertFrom-Base64.md 13 | - ConvertFrom-Base64ToByteArray: functions/ConvertFrom-Base64ToByteArray.md 14 | - ConvertFrom-Base64ToMemoryStream: functions/ConvertFrom-Base64ToMemoryStream.md 15 | - ConvertFrom-Base64ToString: functions/ConvertFrom-Base64ToString.md 16 | - ConvertFrom-ByteArrayToBase64: functions/ConvertFrom-ByteArrayToBase64.md 17 | - ConvertFrom-ByteArrayToMemoryStream: functions/ConvertFrom-ByteArrayToMemoryStream.md 18 | - ConvertFrom-Clixml: functions/ConvertFrom-Clixml.md 19 | - ConvertFrom-CompressedByteArrayToString: functions/ConvertFrom-CompressedByteArrayToString.md 20 | - ConvertFrom-EscapedUrl: functions/ConvertFrom-EscapedUrl.md 21 | - ConvertFrom-MemoryStream: functions/ConvertFrom-MemoryStream.md 22 | - ConvertFrom-MemoryStreamToBase64: functions/ConvertFrom-MemoryStreamToBase64.md 23 | - ConvertFrom-MemoryStreamToByteArray: functions/ConvertFrom-MemoryStreamToByteArray.md 24 | - ConvertFrom-MemoryStreamToString: functions/ConvertFrom-MemoryStreamToString.md 25 | - ConvertFrom-MemoryStreamToSecureString: functions/ConvertFrom-MemoryStreamToSecureString.md 26 | - ConvertFrom-StringToBase64: functions/ConvertFrom-StringToBase64.md 27 | - ConvertFrom-StringToByteArray: functions/ConvertFrom-StringToByteArray.md 28 | - ConvertFrom-StringToCompressedByteArray: functions/ConvertFrom-StringToCompressedByteArray.md 29 | - ConvertFrom-StringToMemoryStream: functions/ConvertFrom-StringToMemoryStream.md 30 | - ConvertFrom-UnixTime: functions/ConvertFrom-UnixTime.md 31 | - ConvertTo-Base64: functions/ConvertTo-Base64.md 32 | - ConvertTo-Clixml: functions/ConvertTo-Clixml.md 33 | - ConvertTo-EscapedUrl: functions/ConvertTo-EscapedUrl.md 34 | - ConvertTo-MemoryStream: functions/ConvertTo-MemoryStream.md 35 | - ConvertTo-String: functions/ConvertTo-String.md 36 | - ConvertTo-TitleCase: functions/ConvertTo-TitleCase.md 37 | - ConvertTo-UnixTime: functions/ConvertTo-UnixTime.md 38 | - Get-UnixTime: functions/Get-UnixTime.md 39 | -------------------------------------------------------------------------------- /publish.ps1: -------------------------------------------------------------------------------- 1 | Import-Module -Name AWS.Tools.CodeBuild 2 | Set-DefaultAWSRegion -Region 'us-west-2' 3 | $buildStatus = foreach ($project in @('austoonz-Convert-Linux', 'austoonz-Convert-Windows')) { 4 | $builds = (Get-CBBuildIdListForProject -ProjectName $project | Select-Object -First 1 | Get-CBBuildBatch).Builds 5 | foreach ($build in $builds) { 6 | [PSCustomObject]([ordered]@{ 7 | Project = $project 8 | ResolvedSourceVersion = $build.ResolvedSourceVersion 9 | BuildStatus = $build.BuildStatus 10 | }) 11 | } 12 | } 13 | 14 | if (($buildStatus.ResolvedSourceVersion | Select-Object -Unique).Count -ne 1) { 15 | Write-Host 'Found to many build versions. Failing...' 16 | } 17 | 18 | $uniqueBuildStatus = ($buildStatus.BuildStatus | Select-Object -Unique).Value 19 | if ($uniqueBuildStatus.Count -ne 1 -and $uniqueBuildStatus -ne 'SUCCEEDED') { 20 | Write-Host 'At least one build failed. Failing...' 21 | } 22 | 23 | Write-Host 'We had a successful build. Finding output artifact...' 24 | -------------------------------------------------------------------------------- /src/Convert/Convert.psm1: -------------------------------------------------------------------------------- 1 | $scriptPath = Split-Path $MyInvocation.MyCommand.Path 2 | try 3 | { 4 | $files = Get-ChildItem -Path $scriptPath -Recurse | Where-Object {$_.Extension -eq '.ps1'} 5 | foreach ($file in $files) 6 | { 7 | . $file.FullName 8 | } 9 | } 10 | catch 11 | { 12 | Write-Warning ('{0}: {1}' -f $Function, $_.Exception.Message) 13 | continue 14 | } 15 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-Base64.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a base64 encoded string to a string. 4 | 5 | .DESCRIPTION 6 | Converts a base64 encoded string to a string. 7 | 8 | .PARAMETER Base64 9 | A Base64 Encoded String. 10 | 11 | .PARAMETER Encoding 12 | The encoding to use for conversion. 13 | Defaults to UTF8. 14 | Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, and UTF8. 15 | 16 | .PARAMETER ToString 17 | Switch parameter to specify a conversion to a string object. 18 | 19 | .PARAMETER Decompress 20 | If supplied, the output will be decompressed using Gzip. 21 | 22 | .EXAMPLE 23 | ConvertFrom-Base64 -Base64 'QSBzdHJpbmc=' -ToString 24 | 25 | A string 26 | 27 | .EXAMPLE 28 | ConvertTo-Base64 -Base64 'A string','Another string' -ToString 29 | 30 | QSBzdHJpbmc= 31 | QW5vdGhlciBzdHJpbmc= 32 | 33 | .EXAMPLE 34 | 'QSBzdHJpbmc=' | ConvertFrom-Base64 -ToString 35 | 36 | A string 37 | 38 | .EXAMPLE 39 | 'QSBzdHJpbmc=','QW5vdGhlciBzdHJpbmc=' | ConvertFrom-Base64 -ToString 40 | 41 | A string 42 | Another string 43 | 44 | .OUTPUTS 45 | [String[]] 46 | 47 | .LINK 48 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64/ 49 | #> 50 | function ConvertFrom-Base64 { 51 | [CmdletBinding( 52 | DefaultParameterSetName = 'Default', 53 | HelpUri = 'http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64/')] 54 | [OutputType('String')] 55 | param 56 | ( 57 | [Parameter( 58 | ParameterSetName = 'Default', 59 | Mandatory = $true, 60 | ValueFromPipeline = $true, 61 | ValueFromPipelineByPropertyName = $true)] 62 | [Parameter( 63 | ParameterSetName = 'ToString', 64 | Mandatory = $true, 65 | ValueFromPipeline = $true, 66 | ValueFromPipelineByPropertyName = $true)] 67 | [ValidateNotNullOrEmpty()] 68 | [Alias('String', 'Base64String')] 69 | [String[]] 70 | $Base64, 71 | 72 | [Parameter(ParameterSetName = 'ToString')] 73 | [ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF7', 'UTF8')] 74 | [String] 75 | $Encoding = 'UTF8', 76 | 77 | [Parameter(ParameterSetName = 'ToString')] 78 | [Parameter(Mandatory = $false)] 79 | [Switch] 80 | $ToString, 81 | 82 | [Parameter(ParameterSetName = 'ToString')] 83 | [Parameter(Mandatory = $false)] 84 | [Switch] 85 | $Decompress 86 | ) 87 | 88 | begin { 89 | $userErrorActionPreference = $ErrorActionPreference 90 | } 91 | 92 | process { 93 | foreach ($b64 in $Base64) { 94 | try { 95 | $bytes = [System.Convert]::FromBase64String($b64) 96 | 97 | if ($ToString) { 98 | if ($Decompress) { 99 | ConvertFrom-CompressedByteArrayToString -ByteArray $bytes -Encoding $Encoding 100 | } else { 101 | [System.Text.Encoding]::$Encoding.GetString($bytes) 102 | } 103 | } else { 104 | $bytes 105 | } 106 | } catch { 107 | Write-Error -ErrorRecord $_ -ErrorAction $userErrorActionPreference 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-Base64ToByteArray.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a Base 64 Encoded String to a Byte Array 4 | 5 | .DESCRIPTION 6 | Converts a Base 64 Encoded String to a Byte Array 7 | 8 | .PARAMETER String 9 | The Base 64 Encoded String to be converted 10 | 11 | .EXAMPLE 12 | PS C:\> ConvertFrom-Base64ToByteArray -String 'dGVzdA==' 13 | 116 14 | 101 15 | 115 16 | 116 17 | 18 | Converts the base64 string to its byte array representation. 19 | 20 | .LINK 21 | https://msdn.microsoft.com/en-us/library/system.convert.frombase64string%28v=vs.110%29.aspx 22 | #> 23 | function ConvertFrom-Base64ToByteArray { 24 | [CmdletBinding()] 25 | [Alias('ConvertFrom-Base64StringToByteArray')] 26 | param 27 | ( 28 | [Parameter(Mandatory = $true)] 29 | [ValidateNotNullOrEmpty()] 30 | [Alias('Base64String')] 31 | [String]$String 32 | ) 33 | [System.Convert]::FromBase64String($String) 34 | } 35 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-Base64ToMemoryStream.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a base64 encoded string to a MemoryStream. 4 | 5 | .DESCRIPTION 6 | Converts a base64 encoded string to a MemoryStream. 7 | 8 | .PARAMETER String 9 | A Base64 Encoded String 10 | 11 | .EXAMPLE 12 | ConvertFrom-Base64ToMemoryStream -String 'QSBzdHJpbmc=' 13 | 14 | .EXAMPLE 15 | ConvertFrom-Base64ToMemoryStream -String 'A string','Another string' 16 | 17 | .EXAMPLE 18 | 'QSBzdHJpbmc=' | ConvertFrom-Base64ToMemoryStream 19 | 20 | .EXAMPLE 21 | 'QSBzdHJpbmc=','QW5vdGhlciBzdHJpbmc=' | ConvertFrom-Base64ToMemoryStream 22 | 23 | .OUTPUTS 24 | [String[]] 25 | 26 | .LINK 27 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64ToMemoryStream/ 28 | #> 29 | function ConvertFrom-Base64ToMemoryStream { 30 | [CmdletBinding(HelpUri = 'http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64ToMemoryStream/')] 31 | [OutputType('System.IO.MemoryStream')] 32 | param 33 | ( 34 | [Parameter( 35 | Mandatory = $true, 36 | ValueFromPipeline = $true, 37 | ValueFromPipelineByPropertyName = $true)] 38 | [ValidateNotNullOrEmpty()] 39 | [Alias('Base64String')] 40 | [String[]] 41 | $String 42 | ) 43 | 44 | begin { 45 | $userErrorActionPreference = $ErrorActionPreference 46 | } 47 | 48 | process { 49 | foreach ($s in $String) { 50 | try { 51 | $byteArray = ConvertFrom-Base64ToByteArray -String $s 52 | ConvertFrom-ByteArrayToMemoryStream -ByteArray $byteArray 53 | } catch { 54 | Write-Error -ErrorRecord $_ -ErrorAction $userErrorActionPreference 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-Base64ToString.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a base64 encoded string to a string. 4 | 5 | .DESCRIPTION 6 | Converts a base64 encoded string to a string. 7 | 8 | .PARAMETER String 9 | A Base64 Encoded String 10 | 11 | .PARAMETER Encoding 12 | The encoding to use for conversion. 13 | Defaults to UTF8. 14 | Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, and UTF8. 15 | 16 | .PARAMETER Decompress 17 | If supplied, the output will be decompressed using Gzip. 18 | 19 | .EXAMPLE 20 | ConvertFrom-Base64ToString -String 'QSBzdHJpbmc=' 21 | 22 | A string 23 | 24 | .EXAMPLE 25 | ConvertTo-Base64 -String 'A string','Another string' 26 | 27 | QSBzdHJpbmc= 28 | QW5vdGhlciBzdHJpbmc= 29 | 30 | .EXAMPLE 31 | 'QSBzdHJpbmc=' | ConvertFrom-Base64ToString 32 | 33 | A string 34 | 35 | .EXAMPLE 36 | 'QSBzdHJpbmc=','QW5vdGhlciBzdHJpbmc=' | ConvertFrom-Base64ToString 37 | 38 | A string 39 | Another string 40 | 41 | .OUTPUTS 42 | [String[]] 43 | 44 | .LINK 45 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64ToString/ 46 | #> 47 | function ConvertFrom-Base64ToString { 48 | [CmdletBinding(HelpUri = 'http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Base64ToString/')] 49 | [OutputType('String')] 50 | [Alias('ConvertFrom-Base64StringToString')] 51 | param 52 | ( 53 | [Parameter( 54 | Mandatory = $true, 55 | ValueFromPipeline = $true, 56 | ValueFromPipelineByPropertyName = $true)] 57 | [ValidateNotNullOrEmpty()] 58 | [Alias('Base64String')] 59 | [String[]] 60 | $String, 61 | 62 | [ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF7', 'UTF8')] 63 | [String] 64 | $Encoding = 'UTF8', 65 | 66 | [Parameter(Mandatory = $false)] 67 | [Switch] 68 | $Decompress 69 | ) 70 | 71 | begin { 72 | $userErrorActionPreference = $ErrorActionPreference 73 | } 74 | 75 | process { 76 | foreach ($s in $String) { 77 | try { 78 | $bytes = [System.Convert]::FromBase64String($s) 79 | 80 | if ($Decompress) { 81 | ConvertFrom-CompressedByteArrayToString -ByteArray $bytes -Encoding $Encoding 82 | } else { 83 | [System.Text.Encoding]::$Encoding.GetString($bytes) 84 | } 85 | } catch { 86 | Write-Error -ErrorRecord $_ -ErrorAction $userErrorActionPreference 87 | } 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-ByteArrayToBase64.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a byte array to a base64 encoded string. 4 | 5 | .DESCRIPTION 6 | Converts a byte array to a base64 encoded string. 7 | 8 | .PARAMETER ByteArray 9 | A byte array object for conversion. 10 | 11 | .PARAMETER Compress 12 | If supplied, the output will be compressed using Gzip. 13 | 14 | .EXAMPLE 15 | $bytes = ConvertFrom-StringToCompressedByteArray -String 'A string' 16 | ConvertFrom-ByteArrayToBase64 -ByteArray $bytes 17 | 18 | H4sIAAAAAAAAC3NUKC4pysxLBwCMN9RgCAAAAA== 19 | 20 | .OUTPUTS 21 | [String[]] 22 | 23 | .LINK 24 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-ByteArrayToBase64/ 25 | #> 26 | function ConvertFrom-ByteArrayToBase64 { 27 | [CmdletBinding(HelpUri = 'http://convert.readthedocs.io/en/latest/functions/ConvertFrom-ByteArrayToBase64/')] 28 | [Alias('ConvertFrom-ByteArrayToBase64String')] 29 | param 30 | ( 31 | [Parameter( 32 | Mandatory = $true, 33 | ValueFromPipeline = $true, 34 | ValueFromPipelineByPropertyName = $true)] 35 | [ValidateNotNullOrEmpty()] 36 | [Alias('Bytes')] 37 | [Byte[]] 38 | $ByteArray, 39 | 40 | [Switch] 41 | $Compress 42 | ) 43 | 44 | begin { 45 | $userErrorActionPreference = $ErrorActionPreference 46 | } 47 | 48 | process { 49 | try { 50 | if ($Compress) { 51 | [System.IO.MemoryStream] $output = [System.IO.MemoryStream]::new() 52 | $gzipStream = [System.IO.Compression.GzipStream]::new($output, ([IO.Compression.CompressionMode]::Compress)) 53 | $gzipStream.Write( $ByteArray, 0, $ByteArray.Length ) 54 | $gzipStream.Close() 55 | $output.Close() 56 | 57 | [System.Convert]::ToBase64String($output.ToArray()) 58 | } else { 59 | [System.Convert]::ToBase64String($ByteArray) 60 | } 61 | } catch { 62 | Write-Error -ErrorRecord $_ -ErrorAction $userErrorActionPreference 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-ByteArrayToMemoryStream.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a Byte Array to a MemoryStream 4 | 5 | .DESCRIPTION 6 | Converts a Byte Array to a MemoryStream 7 | 8 | .PARAMETER ByteArray 9 | The Byte Array to be converted 10 | 11 | .LINK 12 | https://msdn.microsoft.com/en-us/library/system.io.memorystream(v=vs.110).aspx 13 | 14 | .NOTES 15 | Additional information: 16 | https://msdn.microsoft.com/en-us/library/63z365ty(v=vs.110).aspx 17 | 18 | .EXAMPLE 19 | ConvertFrom-ByteArrayToMemoryStream -ByteArray ([Byte[]] (,0xFF * 100)) 20 | 21 | This command uses the ConvertFrom-ByteArrayToMemoryStream cmdlet to convert a Byte Array into a Memory Stream. 22 | #> 23 | function ConvertFrom-ByteArrayToMemoryStream { 24 | param 25 | ( 26 | [Parameter(Mandatory = $true)] 27 | [ValidateNotNullOrEmpty()] 28 | [Alias('Bytes')] 29 | [System.Byte[]]$ByteArray 30 | ) 31 | [System.IO.MemoryStream]::new($ByteArray, 0, $ByteArray.Length) 32 | } 33 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-Clixml.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts Clixml to an object. 4 | 5 | .DESCRIPTION 6 | Converts Clixml to an object. 7 | 8 | .PARAMETER String 9 | Clixml as a string object. 10 | 11 | .EXAMPLE 12 | $xml = @" 13 | 14 | ThisIsMyString 15 | 16 | "@ 17 | ConvertFrom-Clixml -String $xml 18 | 19 | ThisIsMyString 20 | 21 | .EXAMPLE 22 | $xml = @" 23 | 24 | ThisIsMyString 25 | 26 | "@ 27 | $xml | ConvertFrom-Clixml 28 | 29 | ThisIsMyString 30 | 31 | .EXAMPLE 32 | $xml = @" 33 | 34 | ThisIsMyString 35 | 36 | "@ 37 | $xml2 = @" 38 | 39 | This is another string 40 | 41 | "@ 42 | ConvertFrom-Clixml -String $xml,$xml2 43 | 44 | ThisIsMyString 45 | This is another string 46 | 47 | .EXAMPLE 48 | $xml = @" 49 | 50 | ThisIsMyString 51 | 52 | "@ 53 | $xml2 = @" 54 | 55 | This is another string 56 | 57 | "@ 58 | $xml,$xml2 | ConvertFrom-Clixml 59 | 60 | ThisIsMyString 61 | This is another string 62 | 63 | .OUTPUTS 64 | [Object[]] 65 | 66 | .LINK 67 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Clixml/ 68 | #> 69 | function ConvertFrom-Clixml { 70 | [CmdletBinding(HelpUri = 'http://convert.readthedocs.io/en/latest/functions/ConvertFrom-Clixml/')] 71 | param 72 | ( 73 | [Parameter( 74 | Mandatory = $true, 75 | ValueFromPipeline = $true, 76 | ValueFromPipelineByPropertyName = $true)] 77 | [ValidateNotNullOrEmpty()] 78 | [String[]] 79 | $String 80 | ) 81 | 82 | begin { 83 | $userErrorActionPreference = $ErrorActionPreference 84 | Set-Variable -Name 'SPLIT' -Value '(? 36 | function ConvertFrom-CompressedByteArrayToString { 37 | [CmdletBinding(HelpUri = 'http://convert.readthedocs.io/en/latest/functions/ConvertFrom-CompressedByteArrayToString/')] 38 | param 39 | ( 40 | [Parameter( 41 | Mandatory = $true, 42 | ValueFromPipeline = $true, 43 | ValueFromPipelineByPropertyName = $true)] 44 | [ValidateNotNullOrEmpty()] 45 | [Byte[]] 46 | $ByteArray, 47 | 48 | [ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF7', 'UTF8')] 49 | [String] 50 | $Encoding = 'UTF8' 51 | ) 52 | 53 | begin { 54 | $userErrorActionPreference = $ErrorActionPreference 55 | } 56 | 57 | process { 58 | try { 59 | $inputStream = [System.IO.MemoryStream]::new($ByteArray) 60 | $output = [System.IO.MemoryStream]::new() 61 | 62 | $gzipStream = [System.IO.Compression.GzipStream]::new($inputStream, ([IO.Compression.CompressionMode]::Decompress)) 63 | $gzipStream.CopyTo($output) 64 | $gzipStream.Close() 65 | $inputStream.Close() 66 | 67 | [System.Text.Encoding]::$Encoding.GetString($output.ToArray()) 68 | } catch { 69 | Write-Error -ErrorRecord $_ -ErrorAction $userErrorActionPreference 70 | } finally { 71 | if ($inputStream) {$inputStream.Dispose()} 72 | if ($gzipStream) {$gzipStream.Dispose()} 73 | if ($output) {$output.Dispose()} 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-EscapedUrl.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts an escaped URL back to a standard Url. 4 | 5 | .DESCRIPTION 6 | Converts an escaped URL back to a standard Url. 7 | 8 | .PARAMETER Url 9 | The escaped URL to convert. 10 | 11 | .EXAMPLE 12 | PS> ConvertFrom-EscapedUrl -Url 'http%3A%2F%2Ftest.com%3Fvalue%3Dmy%20value' 13 | 14 | Returns the string `http://test.com?value=my value`. 15 | 16 | .OUTPUTS 17 | [string] 18 | 19 | .LINK 20 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-EscapedUrl/ 21 | #> 22 | function ConvertFrom-EscapedUrl { 23 | [CmdletBinding()] 24 | param ( 25 | [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] 26 | [ValidateNotNullOrEmpty()] 27 | [string[]]$Url 28 | ) 29 | 30 | process { 31 | foreach ($u in $Url) { 32 | [System.Uri]::UnescapeDataString($u) 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-HashTable.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts HashTable objects to PSCustomObject objects. 4 | 5 | .DESCRIPTION 6 | Converts HashTable objects to PSCustomObject objects. 7 | 8 | .PARAMETER HashTable 9 | A list of HashTable objects to convert 10 | 11 | .EXAMPLE 12 | PS> ConvertFrom-HashTable -HashTable @{'foo'='bar'} 13 | 14 | Returns a PSCustomObject with the property 'foo' with value 'bar'. 15 | 16 | .EXAMPLE 17 | PS> @{'foo'='bar'} | ConvertFrom-HashTable 18 | 19 | Returns a PSCustomObject with the property 'foo' with value 'bar'. 20 | 21 | .OUTPUTS 22 | [PSCustomObject[]] 23 | 24 | .LINK 25 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-HashTable/ 26 | #> 27 | function ConvertFrom-HashTable { 28 | [CmdletBinding()] 29 | param ( 30 | [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] 31 | [HashTable[]]$HashTable 32 | ) 33 | 34 | process { 35 | foreach ($h in $HashTable) { 36 | [PSCustomObject]$h 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-MemoryStreamToBase64.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts MemoryStream to a base64 encoded string. 4 | 5 | .DESCRIPTION 6 | Converts MemoryStream to a base64 encoded string. 7 | 8 | .PARAMETER MemoryStream 9 | A MemoryStream object for conversion. 10 | 11 | .PARAMETER Encoding 12 | The encoding to use for conversion. 13 | Defaults to UTF8. 14 | Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, and UTF8. 15 | 16 | .EXAMPLE 17 | $string = 'A string' 18 | $stream = [System.IO.MemoryStream]::new() 19 | $writer = [System.IO.StreamWriter]::new($stream) 20 | $writer.Write($string) 21 | $writer.Flush() 22 | 23 | ConvertFrom-MemoryStreamToBase64 -MemoryStream $stream 24 | 25 | QSBzdHJpbmc= 26 | 27 | .EXAMPLE 28 | $string = 'A string' 29 | $stream = [System.IO.MemoryStream]::new() 30 | $writer = [System.IO.StreamWriter]::new($stream) 31 | $writer.Write($string) 32 | $writer.Flush() 33 | 34 | $stream | ConvertFrom-MemoryStreamToBase64 35 | 36 | QSBzdHJpbmc= 37 | 38 | .EXAMPLE 39 | $string1 = 'A string' 40 | $stream1 = [System.IO.MemoryStream]::new() 41 | $writer1 = [System.IO.StreamWriter]::new($stream1) 42 | $writer1.Write($string1) 43 | $writer1.Flush() 44 | 45 | $string2 = 'Another string' 46 | $stream2 = [System.IO.MemoryStream]::new() 47 | $writer2 = [System.IO.StreamWriter]::new($stream2) 48 | $writer2.Write($string2) 49 | $writer2.Flush() 50 | 51 | ConvertFrom-MemoryStreamToBase64 -MemoryStream $stream1,$stream2 52 | 53 | QSBzdHJpbmc= 54 | QW5vdGhlciBzdHJpbmc= 55 | 56 | .EXAMPLE 57 | $string1 = 'A string' 58 | $stream1 = [System.IO.MemoryStream]::new() 59 | $writer1 = [System.IO.StreamWriter]::new($stream1) 60 | $writer1.Write($string1) 61 | $writer1.Flush() 62 | 63 | $string2 = 'Another string' 64 | $stream2 = [System.IO.MemoryStream]::new() 65 | $writer2 = [System.IO.StreamWriter]::new($stream2) 66 | $writer2.Write($string2) 67 | $writer2.Flush() 68 | 69 | $stream1,$stream2 | ConvertFrom-MemoryStreamToBase64 70 | 71 | QSBzdHJpbmc= 72 | QW5vdGhlciBzdHJpbmc= 73 | 74 | .OUTPUTS 75 | [String[]] 76 | 77 | .LINK 78 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToBase64/ 79 | #> 80 | function ConvertFrom-MemoryStreamToBase64 { 81 | [CmdletBinding(HelpUri = 'http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToBase64/')] 82 | param 83 | ( 84 | [Parameter( 85 | Mandatory = $true, 86 | ValueFromPipeline = $true, 87 | ValueFromPipelineByPropertyName = $true)] 88 | [ValidateNotNullOrEmpty()] 89 | [System.IO.MemoryStream[]] 90 | $MemoryStream 91 | ) 92 | 93 | begin { 94 | $userErrorActionPreference = $ErrorActionPreference 95 | } 96 | 97 | process { 98 | foreach ($m in $MemoryStream) { 99 | try { 100 | $byteArray = ConvertFrom-MemoryStreamToByteArray -MemoryStream $m 101 | ConvertFrom-ByteArrayToBase64 -ByteArray $byteArray 102 | } catch { 103 | Write-Error -ErrorRecord $_ -ErrorAction $userErrorActionPreference 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-MemoryStreamToByteArray.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts MemoryStream to a byte array. 4 | 5 | .DESCRIPTION 6 | Converts MemoryStream to a byte array. 7 | 8 | .PARAMETER MemoryStream 9 | A System.IO.MemoryStream object for conversion. 10 | 11 | .PARAMETER Stream 12 | A System.IO.Stream object for conversion. 13 | 14 | .EXAMPLE 15 | $string = 'A string' 16 | $stream = [System.IO.MemoryStream]::new() 17 | $writer = [System.IO.StreamWriter]::new($stream) 18 | $writer.Write($string) 19 | $writer.Flush() 20 | 21 | ConvertFrom-MemoryStreamToByteArray -MemoryStream $stream 22 | 23 | .EXAMPLE 24 | $string = 'A string' 25 | $stream = [System.IO.MemoryStream]::new() 26 | $writer = [System.IO.StreamWriter]::new($stream) 27 | $writer.Write($string) 28 | $writer.Flush() 29 | 30 | $stream | ConvertFrom-MemoryStreamToByteArray 31 | 32 | .EXAMPLE 33 | $string1 = 'A string' 34 | $stream1 = [System.IO.MemoryStream]::new() 35 | $writer1 = [System.IO.StreamWriter]::new($stream1) 36 | $writer1.Write($string1) 37 | $writer1.Flush() 38 | 39 | $string2 = 'Another string' 40 | $stream2 = [System.IO.MemoryStream]::new() 41 | $writer2 = [System.IO.StreamWriter]::new($stream2) 42 | $writer2.Write($string2) 43 | $writer2.Flush() 44 | 45 | ConvertFrom-MemoryStreamToByteArray -MemoryStream $stream1,$stream2 46 | 47 | .EXAMPLE 48 | $string1 = 'A string' 49 | $stream1 = [System.IO.MemoryStream]::new() 50 | $writer1 = [System.IO.StreamWriter]::new($stream1) 51 | $writer1.Write($string1) 52 | $writer1.Flush() 53 | 54 | $string2 = 'Another string' 55 | $stream2 = [System.IO.MemoryStream]::new() 56 | $writer2 = [System.IO.StreamWriter]::new($stream2) 57 | $writer2.Write($string2) 58 | $writer2.Flush() 59 | 60 | $stream1,$stream2 | ConvertFrom-MemoryStreamToByteArray 61 | 62 | .OUTPUTS 63 | [Byte[]] 64 | 65 | .LINK 66 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToByteArray/ 67 | #> 68 | function ConvertFrom-MemoryStreamToByteArray { 69 | [CmdletBinding(HelpUri = 'http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToByteArray/')] 70 | param 71 | ( 72 | [Parameter( 73 | Mandatory = $true, 74 | ValueFromPipeline = $true, 75 | ValueFromPipelineByPropertyName = $true, 76 | ParameterSetName = 'MemoryStream')] 77 | [ValidateNotNullOrEmpty()] 78 | [System.IO.MemoryStream[]] 79 | $MemoryStream, 80 | 81 | [Parameter( 82 | Mandatory = $true, 83 | ValueFromPipelineByPropertyName = $true, 84 | ParameterSetName = 'Stream')] 85 | [ValidateNotNullOrEmpty()] 86 | [System.IO.Stream[]] 87 | $Stream 88 | ) 89 | 90 | begin { 91 | $userErrorActionPreference = $ErrorActionPreference 92 | } 93 | 94 | process { 95 | switch ($PSCmdlet.ParameterSetName) { 96 | 'MemoryStream' { 97 | $inputObject = $MemoryStream 98 | } 99 | 'Stream' { 100 | $inputObject = $Stream 101 | } 102 | } 103 | 104 | foreach ($object in $inputObject) { 105 | try { 106 | if ($PSCmdlet.ParameterSetName -eq 'MemoryStream') { 107 | $object.Position = 0 108 | } 109 | $object.ToArray() 110 | } catch { 111 | Write-Error -ErrorRecord $_ -ErrorAction $userErrorActionPreference 112 | } 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-MemoryStreamToSecureString.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a Memory Stream to a Secure String 4 | 5 | .DESCRIPTION 6 | This cmdlet converts a Memory Stream to a Secure String using a Stream Reader object. 7 | 8 | .PARAMETER MemoryStream 9 | A System.IO.MemoryStream object for conversion. 10 | 11 | .PARAMETER Stream 12 | A System.IO.Stream object for conversion. 13 | 14 | .EXAMPLE 15 | $string = 'My Super Secret Value' 16 | $bytes = [System.Text.Encoding]::UTF8.GetBytes($string) 17 | $memoryStream = [System.IO.MemoryStream]::new($bytes, 0, $bytes.Length) 18 | $secure = ConvertFrom-MemoryStreamToSecureString -MemoryStream $memoryStream 19 | $credential = [PSCredential]::new('MyValue', $secure) 20 | 21 | Converts the provided MemoryStream to a SecureString. 22 | 23 | .LINK 24 | https://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx 25 | 26 | .NOTES 27 | Additional information: 28 | https://msdn.microsoft.com/en-us/library/system.io.streamreader%28v=vs.110%29.aspx 29 | https://msdn.microsoft.com/en-us/library/system.security.securestring%28v=vs.110%29.aspx 30 | #> 31 | function ConvertFrom-MemoryStreamToSecureString { 32 | [CmdletBinding(DefaultParameterSetName = 'MemoryStream')] 33 | param 34 | ( 35 | [Parameter( 36 | Mandatory = $true, 37 | ValueFromPipeline = $true, 38 | ValueFromPipelineByPropertyName = $true, 39 | ParameterSetName = 'MemoryStream')] 40 | [ValidateNotNullOrEmpty()] 41 | [System.IO.MemoryStream[]] 42 | $MemoryStream, 43 | 44 | [Parameter( 45 | Mandatory = $true, 46 | ValueFromPipelineByPropertyName = $true, 47 | ParameterSetName = 'Stream')] 48 | [ValidateNotNullOrEmpty()] 49 | [System.IO.Stream[]] 50 | $Stream 51 | ) 52 | 53 | begin { 54 | $userErrorActionPreference = $ErrorActionPreference 55 | } 56 | 57 | process { 58 | switch ($PSCmdlet.ParameterSetName) { 59 | 'MemoryStream' { 60 | $inputObject = $MemoryStream 61 | } 62 | 'Stream' { 63 | $inputObject = $Stream 64 | } 65 | } 66 | 67 | foreach ($object in $inputObject) { 68 | try { 69 | $secureString = [System.Security.SecureString]::new() 70 | $reader = [System.IO.StreamReader]::new($object) 71 | 72 | while ($reader.Peek() -ge 0) { 73 | $secureString.AppendChar($reader.Read()) 74 | } 75 | $secureString.MakeReadOnly() 76 | 77 | $secureString 78 | } catch { 79 | Write-Error -ErrorRecord $_ -ErrorAction $userErrorActionPreference 80 | } finally { 81 | $reader.Dispose() 82 | } 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-MemoryStreamToString.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts MemoryStream to a string. 4 | 5 | .DESCRIPTION 6 | Converts MemoryStream to a string. 7 | 8 | .PARAMETER MemoryStream 9 | A System.IO.MemoryStream object for conversion. 10 | 11 | .PARAMETER Stream 12 | A System.IO.Stream object for conversion. 13 | 14 | .EXAMPLE 15 | $string = 'A string' 16 | $stream = [System.IO.MemoryStream]::new() 17 | $writer = [System.IO.StreamWriter]::new($stream) 18 | $writer.Write($string) 19 | $writer.Flush() 20 | 21 | ConvertFrom-MemoryStreamToString -MemoryStream $stream 22 | 23 | A string 24 | 25 | .EXAMPLE 26 | $string = 'A string' 27 | $stream = [System.IO.MemoryStream]::new() 28 | $writer = [System.IO.StreamWriter]::new($stream) 29 | $writer.Write($string) 30 | $writer.Flush() 31 | 32 | $stream | ConvertFrom-MemoryStreamToString 33 | 34 | A string 35 | 36 | .EXAMPLE 37 | $string1 = 'A string' 38 | $stream1 = [System.IO.MemoryStream]::new() 39 | $writer1 = [System.IO.StreamWriter]::new($stream1) 40 | $writer1.Write($string1) 41 | $writer1.Flush() 42 | 43 | $string2 = 'Another string' 44 | $stream2 = [System.IO.MemoryStream]::new() 45 | $writer2 = [System.IO.StreamWriter]::new($stream2) 46 | $writer2.Write($string2) 47 | $writer2.Flush() 48 | 49 | ConvertFrom-MemoryStreamToString -MemoryStream $stream1,$stream2 50 | 51 | A string 52 | Another string 53 | 54 | .EXAMPLE 55 | $string1 = 'A string' 56 | $stream1 = [System.IO.MemoryStream]::new() 57 | $writer1 = [System.IO.StreamWriter]::new($stream1) 58 | $writer1.Write($string1) 59 | $writer1.Flush() 60 | 61 | $string2 = 'Another string' 62 | $stream2 = [System.IO.MemoryStream]::new() 63 | $writer2 = [System.IO.StreamWriter]::new($stream2) 64 | $writer2.Write($string2) 65 | $writer2.Flush() 66 | 67 | $stream1,$stream2 | ConvertFrom-MemoryStreamToString 68 | 69 | A string 70 | Another string 71 | 72 | .OUTPUTS 73 | [String[]] 74 | 75 | .LINK 76 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToString/ 77 | #> 78 | function ConvertFrom-MemoryStreamToString { 79 | [CmdletBinding(HelpUri = 'http://convert.readthedocs.io/en/latest/functions/ConvertFrom-MemoryStreamToString/')] 80 | [Alias('ConvertFrom-StreamToString')] 81 | param 82 | ( 83 | [Parameter( 84 | Mandatory = $true, 85 | ValueFromPipeline = $true, 86 | ValueFromPipelineByPropertyName = $true, 87 | ParameterSetName = 'MemoryStream')] 88 | [ValidateNotNullOrEmpty()] 89 | [System.IO.MemoryStream[]] 90 | $MemoryStream, 91 | 92 | [Parameter( 93 | Mandatory = $true, 94 | ValueFromPipelineByPropertyName = $true, 95 | ParameterSetName = 'Stream')] 96 | [ValidateNotNullOrEmpty()] 97 | [System.IO.Stream[]] 98 | $Stream 99 | ) 100 | 101 | begin { 102 | $userErrorActionPreference = $ErrorActionPreference 103 | } 104 | 105 | process { 106 | switch ($PSCmdlet.ParameterSetName) { 107 | 'MemoryStream' { 108 | $inputObject = $MemoryStream 109 | } 110 | 'Stream' { 111 | $inputObject = $Stream 112 | } 113 | } 114 | 115 | foreach ($object in $inputObject) { 116 | try { 117 | if ($PSCmdlet.ParameterSetName -eq 'MemoryStream') { 118 | $object.Position = 0 119 | } 120 | $reader = [System.IO.StreamReader]::new($object) 121 | $reader.ReadToEnd() 122 | } catch { 123 | Write-Error -ErrorRecord $_ -ErrorAction $userErrorActionPreference 124 | } finally { 125 | if ($reader) { 126 | #$reader.Dispose() 127 | } 128 | } 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-StringToBase64.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a string to a base64 encoded string. 4 | 5 | .DESCRIPTION 6 | Converts a string to a base64 encoded string. 7 | 8 | .PARAMETER String 9 | A string object for conversion. 10 | 11 | .PARAMETER Encoding 12 | The encoding to use for conversion. 13 | Defaults to UTF8. 14 | Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, and UTF8. 15 | 16 | .PARAMETER Compress 17 | If supplied, the output will be compressed using Gzip. 18 | 19 | .EXAMPLE 20 | ConvertFrom-StringToBase64 -String 'A string' 21 | QSBzdHJpbmc= 22 | 23 | .EXAMPLE 24 | 'A string' | ConvertFrom-StringToBase64 25 | QSBzdHJpbmc= 26 | 27 | .EXAMPLE 28 | ConvertFrom-StringToBase64 -String 'A string' -Encoding Unicode 29 | QQAgAHMAdAByAGkAbgBnAA== 30 | 31 | .EXAMPLE 32 | 'A string' | ConvertFrom-StringToBase64 -Encoding Unicode 33 | QQAgAHMAdAByAGkAbgBnAA== 34 | 35 | .EXAMPLE 36 | ConvertFrom-StringToBase64 -String 'A string','Another string' 37 | QSBzdHJpbmc= 38 | QW5vdGhlciBzdHJpbmc= 39 | 40 | .EXAMPLE 41 | 'A string','Another string' | ConvertFrom-StringToBase64 42 | QSBzdHJpbmc= 43 | QW5vdGhlciBzdHJpbmc= 44 | 45 | .EXAMPLE 46 | ConvertFrom-StringToBase64 -String 'A string','Another string' -Encoding Unicode 47 | QQAgAHMAdAByAGkAbgBnAA== 48 | QQBuAG8AdABoAGUAcgAgAHMAdAByAGkAbgBnAA== 49 | 50 | .EXAMPLE 51 | 'A string','Another string' | ConvertFrom-StringToBase64 -Encoding Unicode 52 | QQAgAHMAdAByAGkAbgBnAA== 53 | QQBuAG8AdABoAGUAcgAgAHMAdAByAGkAbgBnAA== 54 | 55 | .OUTPUTS 56 | [String[]] 57 | 58 | .LINK 59 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToBase64/ 60 | #> 61 | function ConvertFrom-StringToBase64 { 62 | [CmdletBinding(HelpUri = 'http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToBase64/')] 63 | param 64 | ( 65 | [Parameter( 66 | Mandatory = $true, 67 | ValueFromPipeline = $true, 68 | ValueFromPipelineByPropertyName = $true)] 69 | [ValidateNotNullOrEmpty()] 70 | [String[]] 71 | $String, 72 | 73 | [ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF7', 'UTF8')] 74 | [String] 75 | $Encoding = 'UTF8', 76 | 77 | [Parameter(Mandatory = $false)] 78 | [Switch] 79 | $Compress 80 | ) 81 | 82 | begin { 83 | $userErrorActionPreference = $ErrorActionPreference 84 | } 85 | 86 | process { 87 | foreach ($s in $String) { 88 | try { 89 | if ($Compress) { 90 | $bytes = ConvertFrom-StringToCompressedByteArray -String $s -Encoding $Encoding 91 | } else { 92 | $bytes = [System.Text.Encoding]::$Encoding.GetBytes($s) 93 | } 94 | 95 | [System.Convert]::ToBase64String($bytes) 96 | } catch { 97 | Write-Error -ErrorRecord $_ -ErrorAction $userErrorActionPreference 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-StringToByteArray.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a string to a byte array object. 4 | 5 | .DESCRIPTION 6 | Converts a string to a byte array object. 7 | 8 | .PARAMETER String 9 | A string object for conversion. 10 | 11 | .PARAMETER Encoding 12 | The encoding to use for conversion. 13 | Defaults to UTF8. 14 | Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, and UTF8. 15 | 16 | .EXAMPLE 17 | $bytes = ConvertFrom-StringToByteArray -String 'A string' 18 | $bytes.GetType() 19 | 20 | IsPublic IsSerial Name BaseType 21 | -------- -------- ---- -------- 22 | True True Byte[] System.Array 23 | 24 | $bytes[0].GetType() 25 | 26 | IsPublic IsSerial Name BaseType 27 | -------- -------- ---- -------- 28 | True True Byte System.ValueType 29 | 30 | .EXAMPLE 31 | $bytes = 'A string','Another string' | ConvertFrom-StringToByteArray 32 | 33 | $bytes.Count 34 | 2 35 | 36 | $bytes.GetType() 37 | 38 | IsPublic IsSerial Name BaseType 39 | -------- -------- ---- -------- 40 | True True Object[] System.Array 41 | 42 | $bytes[0].GetType() 43 | 44 | IsPublic IsSerial Name BaseType 45 | -------- -------- ---- -------- 46 | True True Byte[] System.Array 47 | 48 | .OUTPUTS 49 | [System.Collections.Generic.List[Byte[]]] 50 | 51 | .LINK 52 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToByteArray/ 53 | #> 54 | function ConvertFrom-StringToByteArray { 55 | [CmdletBinding(HelpUri = 'http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToByteArray/')] 56 | param 57 | ( 58 | [Parameter( 59 | Mandatory = $true, 60 | ValueFromPipeline = $true, 61 | ValueFromPipelineByPropertyName = $true)] 62 | [ValidateNotNullOrEmpty()] 63 | [String[]] 64 | $String, 65 | 66 | [ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF7', 'UTF8')] 67 | [String] 68 | $Encoding = 'UTF8' 69 | ) 70 | 71 | begin { 72 | $userErrorActionPreference = $ErrorActionPreference 73 | } 74 | 75 | process { 76 | foreach ($s in $String) { 77 | # Creating a generic list to ensure an array of string being handed in 78 | # outputs an array of Byte arrays, rather than a single array with both 79 | # Byte arrays merged. 80 | $byteArrayObject = [System.Collections.Generic.List[Byte[]]]::new() 81 | try { 82 | $byteArray = [System.Text.Encoding]::$Encoding.GetBytes($s) 83 | $null = $byteArrayObject.Add($byteArray) 84 | $byteArrayObject 85 | } catch { 86 | Write-Error -ErrorRecord $_ -ErrorAction $userErrorActionPreference 87 | } 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-StringToCompressedByteArray.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a string to a compressed byte array object. 4 | 5 | .DESCRIPTION 6 | Converts a string to a compressed byte array object. 7 | 8 | .PARAMETER String 9 | A string object for conversion. 10 | 11 | .PARAMETER Encoding 12 | The encoding to use for conversion. 13 | Defaults to UTF8. 14 | Valid options are ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, and UTF8. 15 | 16 | .EXAMPLE 17 | $bytes = ConvertFrom-StringToCompressedByteArray -String 'A string' 18 | $bytes.GetType() 19 | 20 | IsPublic IsSerial Name BaseType 21 | -------- -------- ---- -------- 22 | True True Byte[] System.Array 23 | 24 | $bytes[0].GetType() 25 | 26 | IsPublic IsSerial Name BaseType 27 | -------- -------- ---- -------- 28 | True True Byte System.ValueType 29 | 30 | .OUTPUTS 31 | [System.Collections.Generic.List[Byte[]]] 32 | 33 | .LINK 34 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToCompressedByteArray/ 35 | #> 36 | function ConvertFrom-StringToCompressedByteArray { 37 | [CmdletBinding(HelpUri = 'http://convert.readthedocs.io/en/latest/functions/ConvertFrom-StringToCompressedByteArray/')] 38 | param 39 | ( 40 | [Parameter( 41 | Mandatory = $true, 42 | ValueFromPipeline = $true, 43 | ValueFromPipelineByPropertyName = $true)] 44 | [ValidateNotNullOrEmpty()] 45 | [String[]] 46 | $String, 47 | 48 | [ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF7', 'UTF8')] 49 | [String] 50 | $Encoding = 'UTF8' 51 | ) 52 | 53 | begin { 54 | $userErrorActionPreference = $ErrorActionPreference 55 | } 56 | 57 | process { 58 | foreach ($s in $String) { 59 | # Creating a generic list to ensure an array of string being handed in 60 | # outputs an array of Byte arrays, rather than a single array with both 61 | # Byte arrays merged. 62 | $byteArrayObject = [System.Collections.Generic.List[Byte[]]]::new() 63 | try { 64 | $byteArray = [System.Text.Encoding]::$Encoding.GetBytes($s) 65 | 66 | [System.IO.MemoryStream] $output = [System.IO.MemoryStream]::new() 67 | $gzipStream = [System.IO.Compression.GzipStream]::new($output, ([IO.Compression.CompressionMode]::Compress)) 68 | $gzipStream.Write( $byteArray, 0, $byteArray.Length ) 69 | $gzipStream.Close() 70 | $output.Close() 71 | 72 | $null = $byteArrayObject.Add($output.ToArray()) 73 | $byteArrayObject 74 | } catch { 75 | Write-Error -ErrorRecord $_ -ErrorAction $userErrorActionPreference 76 | } finally { 77 | if ($byteArray) {$byteArray.Clear()} 78 | if ($gzipStream) {$gzipStream.Dispose()} 79 | if ($output) {$output.Dispose()} 80 | } 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /src/Convert/Public/ConvertFrom-UnixTime.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a date time represented in Unix time to a PowerShell DateTime object. 4 | 5 | .DESCRIPTION 6 | Converts a date time represented in Unix time to a PowerShell DateTime object. 7 | 8 | Supports Unix time in seconds by default, or a switch to support Unix time in milliseconds. 9 | 10 | .OUTPUTS 11 | [datetime] 12 | 13 | .LINK 14 | http://convert.readthedocs.io/en/latest/functions/ConvertFrom-UnixTime/ 15 | 16 | .EXAMPLE 17 | ConvertFrom-UnixTime -UnixTime 1674712047 18 | 19 | Thursday, January 26, 2023 5:47:27 AM 20 | 21 | .EXAMPLE 22 | 1674712047 | ConvertFrom-UnixTime 23 | 24 | Thursday, January 26, 2023 5:47:27 AM 25 | 26 | .EXAMPLE 27 | ConvertFrom-UnixTime -UnixTime 1674712048705 -FromMilliseconds 28 | 29 | Thursday, January 26, 2023 5:47:28 AM 30 | 31 | .EXAMPLE 32 | 1674712048705 | ConvertFrom-UnixTime -FromMilliseconds 33 | 34 | Thursday, January 26, 2023 5:47:28 AM 35 | #> 36 | function ConvertFrom-UnixTime { 37 | [CmdletBinding()] 38 | param ( 39 | # The Unix time to convert. Represented in seconds by default, or in milliseconds if the FromMilliseconds 40 | # parameter is specified. 41 | [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] 42 | [long]$UnixTime, 43 | 44 | # If specified, returns the time in milliseconds that have elapsed since 00:00:00 UTC on 1 January, 1970. 45 | [switch]$FromMilliseconds 46 | ) 47 | 48 | process { 49 | if ($FromMilliseconds) { 50 | [datetime]($script:EPOCH_TIME + [System.TimeSpan]::FromMilliseconds($UnixTime)) 51 | } else { 52 | [datetime]($script:EPOCH_TIME + [System.TimeSpan]::FromSeconds($UnixTime)) 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertTo-Celsius.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a temperature from Fahrenheit to Celsius. 4 | 5 | .DESCRIPTION 6 | The ConvertTo-Celsius function converts a temperature value from Fahrenheit to Celsius. 7 | It accepts input via parameter or pipeline, validates that the temperature is not below absolute zero 8 | (-459.67°F), and returns the result rounded to two decimal places. 9 | 10 | .PARAMETER Fahrenheit 11 | The temperature in Fahrenheit to convert. Must be greater than or equal to -459.67°F (absolute zero). 12 | This parameter accepts pipeline input. 13 | 14 | .EXAMPLE 15 | ConvertTo-Celsius -Fahrenheit 32 16 | 0 17 | 18 | Converts 32°F to Celsius (0°C). 19 | 20 | .EXAMPLE 21 | ConvertTo-Celsius -Fahrenheit 98.6 22 | 37 23 | 24 | Converts normal body temperature (98.6°F) to Celsius (37°C). 25 | 26 | .EXAMPLE 27 | 212 | ConvertTo-Celsius 28 | 100 29 | 30 | Demonstrates pipeline input, converting 212°F to Celsius (100°C). 31 | 32 | .EXAMPLE 33 | ConvertTo-Celsius -Fahrenheit -40 34 | -40 35 | 36 | Converts -40°F to Celsius (-40°C), demonstrating the point where both scales intersect. 37 | 38 | .INPUTS 39 | System.Double 40 | You can pipe a double value representing the temperature in Fahrenheit to this function. 41 | 42 | .OUTPUTS 43 | System.Double 44 | Returns the temperature in Celsius as a double value, rounded to two decimal places. 45 | 46 | .NOTES 47 | The formula used is: °C = (°F - 32) × 5/9 48 | 49 | .LINK 50 | ConvertTo-Fahrenheit 51 | 52 | .LINK 53 | https://en.wikipedia.org/wiki/Celsius 54 | #> 55 | function ConvertTo-Celsius { 56 | [CmdletBinding()] 57 | [OutputType([double])] 58 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')] 59 | param ( 60 | [Parameter(Mandatory = $true, 61 | ValueFromPipeline = $true, 62 | Position = 0)] 63 | [ValidateRange(-459.67, [double]::MaxValue)] 64 | [double] 65 | $Fahrenheit 66 | ) 67 | 68 | process { 69 | try { 70 | $celsius = ($Fahrenheit - 32) * 5 / 9 71 | return [Math]::Round($celsius, 2) 72 | } catch { 73 | $PSCmdlet.ThrowTerminatingError( 74 | [System.Management.Automation.ErrorRecord]::new( 75 | $_.Exception.Message, 76 | 'TemperatureConversionError', 77 | [System.Management.Automation.ErrorCategory]::InvalidOperation, 78 | $Fahrenheit 79 | ) 80 | ) 81 | } 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertTo-Clixml.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts an object to Clixml. 4 | 5 | .DESCRIPTION 6 | Converts an object to Clixml. 7 | 8 | .PARAMETER InputObject 9 | The input object to serialize 10 | 11 | .PARAMETER Depth 12 | The depth of the members to serialize 13 | 14 | .EXAMPLE 15 | $string = 'A string' 16 | ConvertTo-Clixml -InputObject $string 17 | 18 | 19 | A string 20 | 21 | 22 | .EXAMPLE 23 | $string = 'A string' 24 | $string | ConvertTo-Clixml 25 | 26 | 27 | A string 28 | 29 | 30 | .EXAMPLE 31 | $string1 = 'A string' 32 | $string2 = 'Another string' 33 | ConvertTo-Clixml -InputObject $string1,$string2 34 | 35 | 36 | A string 37 | 38 | 39 | Another string 40 | 41 | 42 | .EXAMPLE 43 | $string1 = 'A string' 44 | $string2 = 'Another string' 45 | $string1,$string2 | ConvertTo-Clixml 46 | 47 | 48 | A string 49 | 50 | 51 | Another string 52 | 53 | 54 | .OUTPUTS 55 | [String[]] 56 | 57 | .LINK 58 | http://convert.readthedocs.io/en/latest/functions/ConvertTo-Clixml/ 59 | #> 60 | function ConvertTo-Clixml { 61 | [CmdletBinding(HelpUri = 'http://convert.readthedocs.io/en/latest/functions/ConvertTo-Clixml/')] 62 | param 63 | ( 64 | [Parameter( 65 | Mandatory = $true, 66 | ValueFromPipeline = $true, 67 | ValueFromPipelineByPropertyName = $true)] 68 | [ValidateNotNullOrEmpty()] 69 | [PSObject] 70 | $InputObject, 71 | 72 | [Parameter(Mandatory = $false)] 73 | [ValidateRange(1, [Int32]::MaxValue)] 74 | [Int32] 75 | $Depth = 1 76 | ) 77 | 78 | begin { 79 | $userErrorActionPreference = $ErrorActionPreference 80 | } 81 | 82 | process { 83 | foreach ($io in $InputObject) { 84 | try { 85 | [System.Management.Automation.PSSerializer]::Serialize($io, $Depth) 86 | } catch { 87 | Write-Error -ErrorRecord $_ -ErrorAction $userErrorActionPreference 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertTo-EscapedUrl.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a URL to an escaped Url. 4 | 5 | .DESCRIPTION 6 | Converts a URL to an escaped Url. 7 | 8 | .PARAMETER Url 9 | The URL to escape. 10 | 11 | .EXAMPLE 12 | PS> ConvertTo-EscapedUrl -Url 'http://test.com?value=my value' 13 | 14 | Returns the string `http%3A%2F%2Ftest.com%3Fvalue%3Dmy%20value`. 15 | 16 | .OUTPUTS 17 | [string] 18 | 19 | .LINK 20 | http://convert.readthedocs.io/en/latest/functions/ConvertTo-EscapedUrl/ 21 | #> 22 | function ConvertTo-EscapedUrl { 23 | [CmdletBinding()] 24 | param ( 25 | [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] 26 | [ValidateNotNullOrEmpty()] 27 | [string[]]$Url 28 | ) 29 | 30 | process { 31 | foreach ($u in $Url) { 32 | $escaped = [System.Uri]::EscapeDataString($u) 33 | $escaped.Replace("~", '%7E').Replace("'", '%27') 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertTo-Fahrenheit.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a temperature from Celsius to Fahrenheit. 4 | 5 | .DESCRIPTION 6 | The ConvertTo-Fahrenheit function converts a temperature value from Celsius to Fahrenheit. 7 | It accepts input via parameter or pipeline, validates that the temperature is not below absolute zero 8 | (-273.15°C), and returns the result rounded to two decimal places. 9 | 10 | .PARAMETER Celsius 11 | The temperature in Celsius to convert. Must be greater than or equal to -273.15°C (absolute zero). 12 | This parameter accepts pipeline input. 13 | 14 | .EXAMPLE 15 | ConvertTo-Fahrenheit -Celsius 0 16 | 32 17 | 18 | Converts 0°C to Fahrenheit (32°F). 19 | 20 | .EXAMPLE 21 | ConvertTo-Fahrenheit -Celsius 37 22 | 98.6 23 | 24 | Converts body temperature (37°C) to Fahrenheit (98.6°F). 25 | 26 | .EXAMPLE 27 | 100 | ConvertTo-Fahrenheit 28 | 212 29 | 30 | Demonstrates pipeline input, converting 100°C to Fahrenheit (212°F). 31 | 32 | .EXAMPLE 33 | ConvertTo-Fahrenheit -Celsius -40 34 | -40 35 | 36 | Converts -40°C to Fahrenheit (-40°F), demonstrating the point where both scales intersect. 37 | 38 | .INPUTS 39 | System.Double 40 | You can pipe a double value representing the temperature in Celsius to this function. 41 | 42 | .OUTPUTS 43 | System.Double 44 | Returns the temperature in Fahrenheit as a double value, rounded to two decimal places. 45 | 46 | .NOTES 47 | Author: Your Name 48 | Version: 1.0 49 | Date: Current Date 50 | 51 | The formula used is: °F = (°C × 9/5) + 32 52 | 53 | .LINK 54 | ConvertTo-Celsius 55 | 56 | .LINK 57 | https://en.wikipedia.org/wiki/Fahrenheit 58 | #> 59 | function ConvertTo-Fahrenheit { 60 | [CmdletBinding()] 61 | [OutputType([double])] 62 | param ( 63 | [Parameter(Mandatory = $true, 64 | ValueFromPipeline = $true, 65 | Position = 0)] 66 | [ValidateRange(-273.15, [double]::MaxValue)] 67 | [double] 68 | $Celsius 69 | ) 70 | 71 | process { 72 | try { 73 | $fahrenheit = ($Celsius * 9 / 5) + 32 74 | return [Math]::Round($fahrenheit, 2) 75 | } catch { 76 | $PSCmdlet.ThrowTerminatingError( 77 | [System.Management.Automation.ErrorRecord]::new( 78 | $_.Exception.Message, 79 | 'TemperatureConversionError', 80 | [System.Management.Automation.ErrorCategory]::InvalidOperation, 81 | $Celsius 82 | ) 83 | ) 84 | } 85 | } 86 | } 87 | 88 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertTo-Hash.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a string to a hash. 4 | 5 | .DESCRIPTION 6 | Converts a string to a hash. 7 | 8 | .PARAMETER String 9 | A string to convert. 10 | 11 | .PARAMETER Algorithm 12 | The hashing algorithm to use. Defaults to 'SHA256'. 13 | 14 | .EXAMPLE 15 | ConvertTo-Hash -String 'MyString' 16 | 38F92FF0761E08356B7C51C5A1ED88602882C2768F37C2DCC3F0AC6EE3F950F5 17 | 18 | .OUTPUTS 19 | [String[]] 20 | 21 | .LINK 22 | http://convert.readthedocs.io/en/latest/functions/ConvertTo-Hash/ 23 | #> 24 | function ConvertTo-Hash { 25 | [CmdletBinding()] 26 | [Alias('Get-Hash')] 27 | param ( 28 | [Parameter(ParameterSetName='String', ValueFromPipeline, ValueFromPipelineByPropertyName)] 29 | [string[]]$String, 30 | 31 | [ValidateSet('MD5', 'SHA1', 'SHA256', 'SHA384', 'SHA512')] 32 | [string]$Algorithm = 'SHA256', 33 | 34 | [ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF7', 'UTF8')] 35 | [String] 36 | $Encoding = 'UTF8' 37 | ) 38 | 39 | begin { 40 | $hashAlgorithm = [System.Security.Cryptography.HashAlgorithm]::Create($Algorithm) 41 | } 42 | 43 | process { 44 | foreach ($s in $String) { 45 | $sb = [System.Text.StringBuilder]::new() 46 | $hashAlgorithm.ComputeHash([System.Text.Encoding]::$Encoding.GetBytes($s)) | ForEach-Object { 47 | $null = $sb.Append('{0:X2}' -f $_) 48 | } 49 | $sb.ToString() 50 | } 51 | } 52 | 53 | end { 54 | if ($hashAlgorithm) {$hashAlgorithm.Dispose()} 55 | if ($sb) {$null = $sb.Clear()} 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertTo-TitleCase.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Convert a string to title case. 4 | 5 | .DESCRIPTION 6 | Convert a string to title case. 7 | 8 | .PARAMETER String 9 | The string to convert. 10 | 11 | .EXAMPLE 12 | PS> ConvertTo-TitleCase -String 'my string' 13 | 14 | Returns the string `My String`. 15 | 16 | .OUTPUTS 17 | [string] 18 | 19 | .LINK 20 | http://convert.readthedocs.io/en/latest/functions/ConvertTo-TitleCase/ 21 | #> 22 | function ConvertTo-TitleCase { 23 | [CmdletBinding()] 24 | param ( 25 | [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] 26 | [ValidateNotNullOrEmpty()] 27 | [string[]]$String 28 | ) 29 | 30 | process { 31 | foreach ($s in $String) { 32 | ([System.Globalization.CultureInfo]::CurrentCulture).TextInfo.ToTitleCase($s) 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Convert/Public/ConvertTo-UnixTime.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts a date time to the date time represented in Unix time. 4 | 5 | .DESCRIPTION 6 | Converts a date time to the date time represented in Unix time, which is the time in seconds that have elapsed since 7 | 00:00:00 UTC on 1 January, 1970. 8 | 9 | A switch is provided to return the time value represented in milliseconds. 10 | 11 | .OUTPUTS 12 | [long] 13 | 14 | .LINK 15 | http://convert.readthedocs.io/en/latest/functions/ConvertTo-UnixTime/ 16 | 17 | .EXAMPLE 18 | ConvertTo-UnixTime 19 | 20 | 1674712201 21 | 22 | .EXAMPLE 23 | Get-Date | ConvertTo-UnixTime 24 | 25 | 1674683490 26 | 27 | .EXAMPLE 28 | ConvertTo-UnixTime -DateTime (Get-Date).AddMonths(6) 29 | 30 | 1690321833 31 | 32 | .EXAMPLE 33 | ConvertTo-UnixTime -AsMilliseconds 34 | 35 | 1674712253812 36 | #> 37 | function ConvertTo-UnixTime { 38 | [CmdletBinding()] 39 | param ( 40 | # A DateTime object representing the time to convert. Defaults to `[datetime]::UtcNow`. 41 | [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] 42 | [DateTime]$DateTime = [datetime]::UtcNow, 43 | 44 | # If specified, returns the time in milliseconds that have elapsed since 00:00:00 UTC on 1 January, 1970. 45 | [switch]$AsMilliseconds 46 | ) 47 | 48 | process { 49 | if ($AsMilliseconds) { 50 | [long][System.Math]::Round(($DateTime - $script:EPOCH_TIME).TotalMilliseconds) 51 | } else { 52 | [long][System.Math]::Round(($DateTime - $script:EPOCH_TIME).TotalSeconds) 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Convert/Public/Get-UnixTime.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Gets the current date time represented in Unix time. 4 | 5 | .DESCRIPTION 6 | Gets the current date time represented in Unix time, which is the time in seconds that have elapsed since 00:00:00 UTC on 7 | 1 January, 1970. 8 | 9 | A switch is provided to return the time value represented in milliseconds. 10 | 11 | .OUTPUTS 12 | [long] 13 | 14 | .LINK 15 | http://convert.readthedocs.io/en/latest/functions/Get-UnixTime/ 16 | 17 | .EXAMPLE 18 | Get-UnixTime 19 | 20 | 1674712340 21 | 22 | .EXAMPLE 23 | Get-UnixTime -AsMilliseconds 24 | 25 | 1674712353731 26 | #> 27 | function Get-UnixTime { 28 | [CmdletBinding()] 29 | param ( 30 | # If specified, returns the time in milliseconds that have elapsed since 00:00:00 UTC on 1 January, 1970. 31 | [switch]$AsMilliseconds 32 | ) 33 | 34 | if ($AsMilliseconds) { 35 | ConvertTo-UnixTime -DateTime ([datetime]::UtcNow) -AsMilliseconds 36 | } else { 37 | ConvertTo-UnixTime -DateTime ([datetime]::UtcNow) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Convert/_RootModule.ps1: -------------------------------------------------------------------------------- 1 | $script:EPOCH_TIME = (Get-Date -Date '1970-01-01T00:00:00Z').ToUniversalTime() 2 | -------------------------------------------------------------------------------- /src/Tests/Build/Build.Tests.ps1: -------------------------------------------------------------------------------- 1 | Describe -Name 'Module Manifest' -Fixture { 2 | BeforeAll { 3 | $script:ModuleName = 'Convert' 4 | $script:ModuleManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', '..', 'Artifacts', "$ModuleName.psd1") 5 | Import-Module $script:ModuleManifest -Force -ErrorAction 'Stop' 6 | } 7 | 8 | Context -Name 'Exported Functions' -Fixture { 9 | It -Name 'Exports the correct number of functions' -Test { 10 | $assertion = Get-Command -Module $script:ModuleName -CommandType Function 11 | $assertion | Should -HaveCount 31 12 | } 13 | 14 | It -Name '<_>' -TestCases @( 15 | 'ConvertFrom-Base64' 16 | 'ConvertFrom-Base64ToByteArray' 17 | 'ConvertFrom-Base64ToMemoryStream' 18 | 'ConvertFrom-Base64ToString' 19 | 'ConvertFrom-ByteArrayToBase64' 20 | 'ConvertFrom-ByteArrayToMemoryStream' 21 | 'ConvertFrom-Clixml' 22 | 'ConvertFrom-CompressedByteArrayToString' 23 | 'ConvertFrom-EscapedUrl' 24 | 'ConvertFrom-HashTable' 25 | 'ConvertFrom-MemoryStream' 26 | 'ConvertFrom-MemoryStreamToBase64' 27 | 'ConvertFrom-MemoryStreamToByteArray' 28 | 'ConvertFrom-MemoryStreamToSecureString' 29 | 'ConvertFrom-MemoryStreamToString' 30 | 'ConvertFrom-StringToBase64' 31 | 'ConvertFrom-StringToByteArray' 32 | 'ConvertFrom-StringToCompressedByteArray' 33 | 'ConvertFrom-StringToMemoryStream' 34 | 'ConvertFrom-UnixTime' 35 | 'ConvertTo-Base64' 36 | 'ConvertTo-Clixml' 37 | 'ConvertTo-EscapedUrl' 38 | 'ConvertTo-Hash' 39 | 'ConvertTo-MemoryStream' 40 | 'ConvertTo-String' 41 | 'ConvertTo-TitleCase' 42 | 'ConvertTo-UnixTime' 43 | 'Get-UnixTime' 44 | ) -Test { 45 | {Get-Command -Name $_ -Module $script:ModuleName -ErrorAction Stop} | Should -Not -Throw 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-Base64ToByteArray.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe $function { 11 | It 'Returns bytes' { 12 | $text = 'This is a secret and should be hidden' 13 | $bytes = [System.Text.Encoding]::Unicode.GetBytes($text) 14 | $base64String = [Convert]::ToBase64String($bytes) 15 | 16 | $assertion = ConvertFrom-Base64ToByteArray -String $base64String 17 | $assertion | Should -BeOfType 'byte' 18 | } 19 | 20 | It 'Throws an exception when input is a string of incorrect length' { 21 | { ConvertFrom-Base64ToByteArray -String 'String' } | Should -Throw 22 | } 23 | 24 | It 'Throws an exception when input is of wrong type' { 25 | { ConvertFrom-Base64ToByteArray -String (New-Object -TypeName PSObject) } | Should -Throw 26 | } 27 | 28 | It 'Throws an exception when input is null' { 29 | { ConvertFrom-Base64ToByteArray -String $null } | Should -Throw 30 | } 31 | 32 | It 'Throws an exception when input is empty' { 33 | { ConvertFrom-Base64ToByteArray -String '' } | Should -Throw 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-Base64ToMemoryStream.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $Base64 = 'VGhpc0lzTXlTdHJpbmc=' 13 | $Expected = 'ThisIsMyString' 14 | 15 | # Use the variables so IDe does not complain 16 | $null = $Base64, $Expected 17 | } 18 | 19 | Context -Name 'Happy Path' -Fixture { 20 | It -Name "Converts a string to a memory stream" -Test { 21 | $assertion = ConvertFrom-Base64ToMemoryStream -String $Base64 22 | $assertion | Should -BeOfType 'System.IO.MemoryStream' 23 | } 24 | 25 | It -Name 'Supports the Pipeline' -Test { 26 | $assertion = $Base64 | ConvertFrom-Base64ToMemoryStream 27 | $assertion | Should -BeOfType 'System.IO.MemoryStream' 28 | } 29 | 30 | It -Name 'Supports EAP SilentlyContinue' -Test { 31 | $assertion = ConvertFrom-Base64ToMemoryStream -String ([int]1) -ErrorAction SilentlyContinue 32 | $assertion | Should -BeNullOrEmpty 33 | } 34 | 35 | It -Name 'Supports EAP Stop' -Test { 36 | { ConvertFrom-Base64ToMemoryStream -String ([int]1) -ErrorAction Stop } | Should -Throw 37 | } 38 | 39 | It -Name 'Supports EAP Continue' -Test { 40 | $assertion = ConvertFrom-Base64ToMemoryStream -String ([int]1) -ErrorAction Continue 2>&1 41 | 42 | $exception = @( 43 | # PowerShell 44 | 'The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.' 45 | 46 | # Windows PowerShell 47 | 'Invalid length for a Base-64 char array or string.' 48 | ) 49 | $assertion.Exception.InnerException.Message | Should -BeIn $exception 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-Base64ToString.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $Expected = 'ThisIsMyString' 13 | 14 | # Use the variables so IDe does not complain 15 | $null = $Expected 16 | } 17 | 18 | Context -Name '' -ForEach @( 19 | @{ 20 | Encoding = 'ASCII' 21 | Base64 = 'VGhpc0lzTXlTdHJpbmc=' 22 | } 23 | @{ 24 | Encoding = 'BigEndianUnicode' 25 | Base64 = 'AFQAaABpAHMASQBzAE0AeQBTAHQAcgBpAG4AZw==' 26 | } 27 | @{ 28 | Encoding = 'Default' 29 | Base64 = 'VGhpc0lzTXlTdHJpbmc=' 30 | } 31 | @{ 32 | Encoding = 'Unicode' 33 | Base64 = 'VABoAGkAcwBJAHMATQB5AFMAdAByAGkAbgBnAA==' 34 | } 35 | @{ 36 | Encoding = 'UTF32' 37 | Base64 = 'VAAAAGgAAABpAAAAcwAAAEkAAABzAAAATQAAAHkAAABTAAAAdAAAAHIAAABpAAAAbgAAAGcAAAA=' 38 | } 39 | @{ 40 | Encoding = 'UTF7' 41 | Base64 = 'VGhpc0lzTXlTdHJpbmc=' 42 | } 43 | @{ 44 | Encoding = 'UTF8' 45 | Base64 = 'VGhpc0lzTXlTdHJpbmc=' 46 | } 47 | ) -Fixture { 48 | It -Name "Converts a Encoded string to a string" -Test { 49 | $splat = @{ 50 | String = $Base64 51 | Encoding = $Encoding 52 | } 53 | $assertion = ConvertFrom-Base64ToString @splat 54 | $assertion | Should -BeExactly $Expected 55 | } 56 | 57 | It -Name 'Supports the Pipeline' -Test { 58 | $assertion = $Base64 | ConvertFrom-Base64ToString -Encoding $Encoding 59 | $assertion | Should -BeExactly $Expected 60 | } 61 | 62 | It -Name 'Supports EAP SilentlyContinue' -Test { 63 | $splat = @{ 64 | String = 'a' 65 | Encoding = $Encoding 66 | } 67 | $assertion = ConvertFrom-Base64ToString @splat -ErrorAction SilentlyContinue 68 | $assertion | Should -BeNullOrEmpty 69 | } 70 | 71 | It -Name 'Supports EAP Stop' -Test { 72 | $splat = @{ 73 | String = 'a' 74 | Encoding = $Encoding 75 | } 76 | { ConvertFrom-Base64ToString @splat -ErrorAction Stop } | Should -Throw 77 | } 78 | 79 | It -Name 'Supports EAP Continue' -Test { 80 | $splat = @{ 81 | String = 'a' 82 | Encoding = $Encoding 83 | } 84 | $assertion = ConvertFrom-Base64ToString @splat -ErrorAction Continue 2>&1 85 | 86 | $exception = @( 87 | 'Invalid length for a Base-64 char array or string.', 88 | 'The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.' 89 | ) 90 | $assertion.Exception.InnerException.Message | Should -BeIn $exception 91 | } 92 | } 93 | } 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-ByteArrayToBase64.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe $function { 11 | BeforeAll { 12 | $string = ConvertTo-Json -InputObject @{ 13 | Hello = 'World' 14 | Foo = 'Bar' 15 | } 16 | $bytes = [System.Text.Encoding]::Unicode.GetBytes($string) 17 | $null = $string, $bytes 18 | } 19 | It 'Returns a Base64 Encoded String' { 20 | $assertion = ConvertFrom-ByteArrayToBase64 -ByteArray $bytes 21 | $assertion | ConvertFrom-Base64ToString | Should -BeExactly $string 22 | $assertion | Should -BeOfType 'String' 23 | } 24 | 25 | It 'Returns a Base64 Encoded String with compression' { 26 | $assertion = ConvertFrom-ByteArrayToBase64 -ByteArray $bytes -Compress 27 | $assertion | ConvertFrom-Base64ToString -Decompress | Should -BeExactly $string 28 | $assertion | Should -BeOfType 'String' 29 | } 30 | 31 | It 'Returns the correct value when the input is an empty string' { 32 | $expected = 'AA==' 33 | $assertion = ConvertFrom-ByteArrayToBase64 -ByteArray '' 34 | $assertion | Should -BeExactly $expected 35 | } 36 | 37 | It 'Throws an exception when input is of wrong type' { 38 | { ConvertFrom-ByteArrayToBase64 -ByteArray (New-Object -TypeName PSObject) } | Should -Throw 39 | } 40 | 41 | It 'Throws an exception when input is null' { 42 | { ConvertFrom-ByteArrayToBase64 -ByteArray $null } | Should -Throw 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-ByteArrayToMemoryStream.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe $function { 11 | It 'Returns a MemoryStream' { 12 | $byteArray = [Byte[]] (, 0xFF * 100) 13 | 14 | $assertion = ConvertFrom-ByteArrayToMemoryStream -ByteArray $byteArray 15 | $assertion.GetType().Name | Should -BeExactly 'MemoryStream' 16 | } 17 | It 'Does not throw an exception when input is an empty System.Byte' { 18 | { ConvertFrom-ByteArrayToMemoryStream -ByteArray (New-Object -TypeName System.Byte) } | Should -Not -Throw 19 | } 20 | 21 | It 'Does not throw an exception when input is empty' { 22 | { ConvertFrom-ByteArrayToMemoryStream -ByteArray '' } | Should -Not -Throw 23 | } 24 | 25 | It 'Throws an exception when input is of wrong type' { 26 | { ConvertFrom-ByteArrayToMemoryStream -ByteArray (New-Object -TypeName PSObject) } | Should -Throw 27 | } 28 | 29 | It 'Throws an exception when input is null' { 30 | { ConvertFrom-ByteArrayToMemoryStream -ByteArray $null } | Should -Throw 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-Clixml.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $Expected = 'ThisIsMyString' 13 | $Xml = @" 14 | 15 | ThisIsMyString 16 | 17 | "@ 18 | 19 | $ExpectedFirstString = 'ThisIsMyFirstString' 20 | $ExpectedSecondString = 'ThisIsMySecondString' 21 | $ExpectedThirdString = 'ThisIsMyThirdString' 22 | $MultipleXmlRecords = @" 23 | 24 | ThisIsMyFirstString 25 | 26 | 27 | ThisIsMySecondString 28 | 29 | 30 | ThisIsMyThirdString 31 | 32 | "@ 33 | 34 | # Use the variables so IDe does not complain 35 | $null = $Expected, $Xml, $ExpectedFirstString, $ExpectedSecondString, $ExpectedThirdString, $MultipleXmlRecords 36 | } 37 | 38 | Context -Name 'Input/Output' -Fixture { 39 | It -Name "Converts from Clixml correctly" -Test { 40 | $assertion = ConvertFrom-Clixml -String $Xml 41 | $assertion | Should -BeExactly $Expected 42 | } 43 | 44 | It -Name "Converts s tingle string with multiple Clixml records correctly" -Test { 45 | $assertion = ConvertFrom-Clixml -String $MultipleXmlRecords 46 | $assertion | Should -HaveCount 3 47 | $assertion[0] | Should -BeExactly $ExpectedFirstString 48 | $assertion[1] | Should -BeExactly $ExpectedSecondString 49 | $assertion[2] | Should -BeExactly $ExpectedThirdString 50 | } 51 | } 52 | 53 | Context -Name 'Pipeline' -Fixture { 54 | It -Name 'Supports the Pipeline' -Test { 55 | $assertion = $Xml | ConvertFrom-Clixml 56 | $assertion | Should -BeExactly $Expected 57 | } 58 | 59 | It -Name 'Supports the Pipeline with array input' -Test { 60 | $assertion = $Xml, $Xml | ConvertFrom-Clixml 61 | $assertion | Should -HaveCount 2 62 | } 63 | 64 | It -Name 'Supports a string with multiple Clixml records' -Test { 65 | $assertion = $MultipleXmlRecords | ConvertFrom-Clixml 66 | $assertion | Should -HaveCount 3 67 | $assertion[0] | Should -BeExactly $ExpectedFirstString 68 | $assertion[1] | Should -BeExactly $ExpectedSecondString 69 | $assertion[2] | Should -BeExactly $ExpectedThirdString 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-CompressedByteArrayToString.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $Expected = 'ThisIsMyString' 13 | 14 | # Use the variables so IDe does not complain 15 | $null = $Expected 16 | } 17 | 18 | Context -Name '' -ForEach @( 19 | @{ 20 | Encoding = 'ASCII' 21 | Bytes = @(31, 139, 8, 0, 0, 0, 0, 0, 4, 0, 11, 201, 200, 44, 246, 44, 246, 173, 12, 46, 41, 202, 204, 75, 7, 0, 155, 209, 238, 33, 14, 0, 0, 0) 22 | } 23 | @{ 24 | Encoding = 'BigEndianUnicode' 25 | Bytes = @(31, 139, 8, 0, 0, 0, 0, 0, 4, 0, 99, 8, 97, 200, 96, 200, 100, 40, 102, 240, 4, 98, 95, 134, 74, 134, 96, 134, 18, 134, 34, 160, 72, 30, 67, 58, 0, 14, 106, 112, 104, 28, 0, 0, 0) 26 | } 27 | @{ 28 | Encoding = 'Default' 29 | Bytes = @(31, 139, 8, 0, 0, 0, 0, 0, 4, 0, 11, 201, 200, 44, 246, 44, 246, 173, 12, 46, 41, 202, 204, 75, 7, 0, 155, 209, 238, 33, 14, 0, 0, 0) 30 | } 31 | @{ 32 | Encoding = 'Unicode' 33 | Bytes = @(31, 139, 8, 0, 0, 0, 0, 0, 4, 0, 11, 97, 200, 96, 200, 100, 40, 102, 240, 4, 98, 95, 134, 74, 134, 96, 134, 18, 134, 34, 160, 72, 30, 67, 58, 3, 0, 47, 0, 246, 190, 28, 0, 0, 0) 34 | } 35 | @{ 36 | Encoding = 'UTF32' 37 | Bytes = @(31, 139, 8, 0, 0, 0, 0, 0, 4, 0, 11, 97, 96, 96, 200, 0, 226, 76, 32, 46, 6, 98, 79, 40, 237, 11, 196, 149, 64, 28, 12, 196, 37, 64, 92, 4, 85, 147, 7, 196, 233, 64, 12, 0, 199, 38, 120, 35, 56, 0, 0, 0) 38 | } 39 | @{ 40 | Encoding = 'UTF7' 41 | Bytes = @(31, 139, 8, 0, 0, 0, 0, 0, 4, 0, 11, 201, 200, 44, 246, 44, 246, 173, 12, 46, 41, 202, 204, 75, 7, 0, 155, 209, 238, 33, 14, 0, 0, 0) 42 | } 43 | @{ 44 | Encoding = 'UTF8' 45 | Bytes = @(31, 139, 8, 0, 0, 0, 0, 0, 4, 0, 11, 201, 200, 44, 246, 44, 246, 173, 12, 46, 41, 202, 204, 75, 7, 0, 155, 209, 238, 33, 14, 0, 0, 0) 46 | } 47 | ) -Fixture { 48 | It -Name 'Converts a encoded compressed byte array to a string' -Test { 49 | $splat = @{ 50 | ByteArray = $Bytes 51 | Encoding = $Encoding 52 | } 53 | $assertion = ConvertFrom-CompressedByteArrayToString @splat 54 | $assertion | Should -BeExactly $Expected 55 | } 56 | 57 | It -Name 'Supports the Pipeline' -Test { 58 | $bytes = $Bytes 59 | $assertion = , $bytes | ConvertFrom-CompressedByteArrayToString -Encoding $Encoding 60 | $assertion | Should -BeExactly $Expected 61 | } 62 | 63 | It -Name 'Supports EAP SilentlyContinue' -Test { 64 | $splat = @{ 65 | ByteArray = @(0, 1) 66 | Encoding = $Encoding 67 | } 68 | $assertion = ConvertFrom-CompressedByteArrayToString @splat -ErrorAction SilentlyContinue 69 | $assertion | Should -BeNullOrEmpty 70 | } 71 | 72 | It -Name 'Supports EAP Stop' -Test { 73 | $splat = @{ 74 | ByteArray = @(0, 1) 75 | Encoding = $Encoding 76 | } 77 | { ConvertFrom-CompressedByteArrayToString @splat -ErrorAction Stop } | Should -Throw 78 | } 79 | 80 | It -Name 'Supports EAP Continue' -Test { 81 | $splat = @{ 82 | ByteArray = @(0, 1) 83 | Encoding = $Encoding 84 | } 85 | $assertion = ConvertFrom-CompressedByteArrayToString @splat -ErrorAction Continue 2>&1 86 | 87 | $Expected = @( 88 | 'The archive entry was compressed using an unsupported compression method.', 89 | 'The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.' 90 | ) 91 | 92 | $assertion.Exception.InnerException.Message | Should -BeIn $Expected 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-EscapedUrl.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe $function { 11 | It 'Converts an escaped URL to a URL' { 12 | $url = 'http%3A%2F%2Ftest.com%3Fvalue%3Dmy%20%23%24%25%40%60%2F%3A%3B%3C%3D%3E%3F%5B%5C%5D%5E%7B%7C%7D~%22%27%2B%2Cvalue' 13 | $expected = 'http://test.com?value=my #$%@`/:;<=>?[\]^{|}~"' + "'" + '+,value' 14 | 15 | $assertion = ConvertFrom-EscapedUrl -Url $url 16 | $assertion | Should -BeExactly $expected 17 | } 18 | 19 | It 'Supports the PowerShell pipeline' { 20 | $url = 'http%3A%2F%2Ftest.com%3Fvalue%3Dmy%20%23%24%25%40%60%2F%3A%3B%3C%3D%3E%3F%5B%5C%5D%5E%7B%7C%7D~%22%27%2B%2Cvalue' 21 | $expected = 'http://test.com?value=my #$%@`/:;<=>?[\]^{|}~"' + "'" + '+,value' 22 | 23 | $assertion = $Url,$Url | ConvertFrom-EscapedUrl 24 | $assertion | Should -BeExactly $expected,$expected 25 | } 26 | 27 | It 'Supports the PowerShell pipeline by value name' { 28 | $url = [PSCustomObject]@{ 29 | Url = 'http%3A%2F%2Ftest.com%3Fvalue%3Dmy%20%23%24%25%40%60%2F%3A%3B%3C%3D%3E%3F%5B%5C%5D%5E%7B%7C%7D~%22%27%2B%2Cvalue' 30 | } 31 | $expected = 'http://test.com?value=my #$%@`/:;<=>?[\]^{|}~"' + "'" + '+,value' 32 | 33 | $assertion = $Url | ConvertFrom-EscapedUrl 34 | $assertion | Should -BeExactly $expected 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-HashTable.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe $function { 11 | BeforeAll { 12 | $foo = 'foo' 13 | $bar = 'bar' 14 | $ht = @{$foo = $bar} 15 | $null = $foo, $bar, $ht 16 | 17 | function ValidateAssertion { 18 | param ($Assertion) 19 | $assertion | Should -BeOfType 'PSCustomObject' 20 | ($assertion | Get-Member -MemberType NoteProperty | Where-Object {$_.Name}).Name | Should -BeExactly $foo 21 | $assertion.$foo | Should -BeExactly $bar 22 | 23 | } 24 | } 25 | 26 | It 'Converts a HashTable to a PSCustomObject' { 27 | $assertion = ConvertFrom-HashTable -HashTable $ht 28 | ValidateAssertion $assertion 29 | } 30 | 31 | It 'Supports the PowerShell pipeline' { 32 | $assertion = $ht | ConvertFrom-HashTable 33 | ValidateAssertion $assertion 34 | 35 | $assertion = $ht,$ht | ConvertFrom-HashTable 36 | ValidateAssertion $assertion[0] 37 | ValidateAssertion $assertion[1] 38 | } 39 | 40 | It 'Supports the PowerShell pipeline by value name' { 41 | $pipelineObject = [PSCustomObject]@{ 42 | HashTable = $ht 43 | } 44 | 45 | $assertion = $pipelineObject | ConvertFrom-HashTable 46 | ValidateAssertion $assertion 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-MemoryStreamToSecureString.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe $function { 11 | It 'Returns a SecureString' { 12 | $string = 'Hello world!' 13 | $bytes = [System.Text.Encoding]::UTF8.GetBytes($string) 14 | $memoryStream = [System.IO.MemoryStream]::new($bytes, 0, $bytes.Length) 15 | 16 | $assertion = ConvertFrom-MemoryStreamToSecureString -MemoryStream $memoryStream 17 | $assertion | Should -BeOfType 'SecureString' 18 | 19 | $credential = [PSCredential]::new('DummyValue', $assertion) 20 | $credential.GetNetworkCredential().Password | Should -BeExactly $string 21 | } 22 | 23 | It 'Throws an exception when input is of wrong type' { 24 | { ConvertFrom-MemoryStreamToSecureString -MemoryStream 'String' } | Should -Throw 25 | } 26 | 27 | It 'Throws an exception when input is null' { 28 | { ConvertFrom-MemoryStreamToSecureString -MemoryStream $null } | Should -Throw 29 | } 30 | 31 | It 'Does not throw an exception when input is an empty System.IO.MemoryStream' { 32 | { ConvertFrom-MemoryStreamToSecureString -MemoryStream (New-Object System.IO.MemoryStream) } | Should -Not -Throw 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-StringToBase64.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $String = 'ThisIsMyString' 13 | 14 | # Use the variables so IDe does not complain 15 | $null = $String 16 | } 17 | 18 | Context -Name 'Input/Output' -ForEach @( 19 | @{ 20 | Encoding = 'ASCII' 21 | Expected = 'VGhpc0lzTXlTdHJpbmc=' 22 | } 23 | @{ 24 | Encoding = 'BigEndianUnicode' 25 | Expected = 'AFQAaABpAHMASQBzAE0AeQBTAHQAcgBpAG4AZw==' 26 | } 27 | @{ 28 | Encoding = 'Default' 29 | Expected = 'VGhpc0lzTXlTdHJpbmc=' 30 | } 31 | @{ 32 | Encoding = 'Unicode' 33 | Expected = 'VABoAGkAcwBJAHMATQB5AFMAdAByAGkAbgBnAA==' 34 | } 35 | @{ 36 | Encoding = 'UTF32' 37 | Expected = 'VAAAAGgAAABpAAAAcwAAAEkAAABzAAAATQAAAHkAAABTAAAAdAAAAHIAAABpAAAAbgAAAGcAAAA=' 38 | } 39 | @{ 40 | Encoding = 'UTF7' 41 | Expected = 'VGhpc0lzTXlTdHJpbmc=' 42 | } 43 | @{ 44 | Encoding = 'UTF8' 45 | Expected = 'VGhpc0lzTXlTdHJpbmc=' 46 | } 47 | ) -Fixture { 48 | Context -Name '' -Fixture { 49 | It -Name 'Converts a string to a Encoded string' -Test { 50 | $splat = @{ 51 | String = $String 52 | Encoding = $Encoding 53 | } 54 | $assertion = ConvertFrom-StringToBase64 @splat 55 | $assertion | Should -BeExactly $Expected 56 | } 57 | } 58 | } 59 | 60 | Context -Name 'Pipeline' -Fixture { 61 | It -Name 'Supports the Pipeline' -Test { 62 | $assertion = $String | ConvertFrom-StringToBase64 -Encoding 'UTF8' 63 | $assertion | Should -BeExactly 'VGhpc0lzTXlTdHJpbmc=' 64 | } 65 | 66 | It -Name 'Supports the Pipeline with array input' -Test { 67 | $assertion = @($String, $String) | ConvertFrom-StringToBase64 -Encoding 'UTF8' 68 | $assertion | Should -HaveCount 2 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-StringToByteArray.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $String = 'ThisIsMyString' 13 | 14 | # Use the variables so IDe does not complain 15 | $null = $String 16 | } 17 | 18 | Context -Name '' -ForEach @( 19 | @{ 20 | Encoding = 'ASCII' 21 | Expected = @(84, 104, 105, 115, 73, 115, 77, 121, 83, 116, 114, 105, 110, 103) 22 | } 23 | @{ 24 | Encoding = 'BigEndianUnicode' 25 | Expected = @(0, 84, 0, 104, 0, 105, 0, 115, 0, 73, 0, 115, 0, 77, 0, 121, 0, 83, 0, 116, 0, 114, 0, 105, 0, 110, 0, 103) 26 | } 27 | @{ 28 | Encoding = 'Default' 29 | Expected = @(84, 104, 105, 115, 73, 115, 77, 121, 83, 116, 114, 105, 110, 103) 30 | } 31 | @{ 32 | Encoding = 'Unicode' 33 | Expected = @(84, 0, 104, 0, 105, 0, 115, 0, 73, 0, 115, 0, 77, 0, 121, 0, 83, 0, 116, 0, 114, 0, 105, 0, 110, 0, 103, 0) 34 | } 35 | @{ 36 | Encoding = 'UTF32' 37 | Expected = @(84, 0, 0, 0, 104, 0, 0, 0, 105, 0, 0, 0, 115, 0, 0, 0, 73, 0, 0, 0, 115, 0, 0, 0, 77, 0, 0, 0, 121, 0, 0, 0, 83, 0, 0, 0, 116, 0, 0, 0, 114, 0, 0, 0, 105, 0, 0, 0, 110, 0, 0, 0, 103, 0, 0, 0) 38 | } 39 | @{ 40 | Encoding = 'UTF7' 41 | Expected = @(84, 104, 105, 115, 73, 115, 77, 121, 83, 116, 114, 105, 110, 103) 42 | } 43 | @{ 44 | Encoding = 'UTF8' 45 | Expected = @(84, 104, 105, 115, 73, 115, 77, 121, 83, 116, 114, 105, 110, 103) 46 | } 47 | ) -Fixture { 48 | It -Name 'Converts a Encoded string to a byte array' -Test { 49 | $splat = @{ 50 | String = $String 51 | Encoding = $Encoding 52 | } 53 | $assertion = ConvertFrom-StringToByteArray @splat 54 | $assertion | Should -BeExactly $Expected 55 | } 56 | 57 | It -Name 'Supports the Pipeline' -Test { 58 | $assertion = $String | ConvertFrom-StringToByteArray -Encoding $Encoding 59 | $assertion | Should -BeExactly $Expected 60 | } 61 | 62 | It -Name 'Outputs an array of arrays' -Test { 63 | $assertion = ConvertFrom-StringToByteArray -String @($String, $String) -Encoding $Encoding 64 | $assertion.Count | Should -BeExactly 2 65 | $assertion[0].GetType().Name | Should -BeExactly 'Byte[]' 66 | $assertion[1].GetType().Name | Should -BeExactly 'Byte[]' 67 | } 68 | 69 | It -Name 'Outputs an array of arrays from the Pipeline' -Test { 70 | $assertion = $String, $String | ConvertFrom-StringToByteArray -Encoding $Encoding 71 | $assertion.Count | Should -BeExactly 2 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-StringToCompressedByteArray.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $String = 'ThisIsMyString' 13 | 14 | # Use the variables so IDe does not complain 15 | $null = $String 16 | 17 | function GetExpected { 18 | param( 19 | $ExpectedDesktop, 20 | $ExpectedLinux, 21 | $ExpectedCorePS6, 22 | $ExpectedCorePS7, 23 | $ExpectedCore 24 | ) 25 | if ($PSEdition -eq 'Desktop') { 26 | return $ExpectedDesktop 27 | } elseif ($IsLinux) { 28 | return $ExpectedLinux 29 | } elseif ($IsMacOS) { 30 | return $ExpectedMacOS 31 | } elseif ($PSVersionTable.PSVersion.Major -eq 6) { 32 | return $ExpectedCorePS6 33 | } elseif ($PSVersionTable.PSVersion.Major -eq 7) { 34 | return $ExpectedCorePS7 35 | } else { 36 | return $ExpectedCore 37 | } 38 | } 39 | } 40 | Context -Name '' -ForEach @( 41 | @{Encoding = 'ASCII' } 42 | @{Encoding = 'BigEndianUnicode' } 43 | @{Encoding = 'Default' } 44 | @{Encoding = 'Unicode' } 45 | @{Encoding = 'UTF32' } 46 | @{Encoding = 'UTF7' } 47 | @{Encoding = 'UTF8' } 48 | ) -Fixture { 49 | It -Name 'Converts a Encoded string to a byte array' -Test { 50 | $splat = @{ 51 | String = $String 52 | Encoding = $Encoding 53 | } 54 | $byteArray = ConvertFrom-StringToCompressedByteArray @splat 55 | $inputStream = [System.IO.MemoryStream]::new($byteArray) 56 | $output = [System.IO.MemoryStream]::new() 57 | $gzipStream = [System.IO.Compression.GzipStream]::new($inputStream, ([IO.Compression.CompressionMode]::Decompress)) 58 | $gzipStream.CopyTo($output) 59 | $gzipStream.Close() 60 | $inputStream.Close() 61 | $assertion = [System.Text.Encoding]::$Encoding.GetString($output.ToArray()) 62 | $assertion | Should -BeExactly $String 63 | } 64 | 65 | It -Name 'Supports the Pipeline' -Test { 66 | $byteArray = $String | ConvertFrom-StringToCompressedByteArray -Encoding $Encoding 67 | $inputStream = [System.IO.MemoryStream]::new($byteArray) 68 | $output = [System.IO.MemoryStream]::new() 69 | $gzipStream = [System.IO.Compression.GzipStream]::new($inputStream, ([IO.Compression.CompressionMode]::Decompress)) 70 | $gzipStream.CopyTo($output) 71 | $gzipStream.Close() 72 | $inputStream.Close() 73 | $assertion = [System.Text.Encoding]::$Encoding.GetString($output.ToArray()) 74 | $assertion | Should -BeExactly $String 75 | } 76 | 77 | It -Name 'Outputs an array of arrays' -Test { 78 | $assertion = ConvertFrom-StringToCompressedByteArray -String @($String, $String) -Encoding $Encoding 79 | $assertion.Count | Should -BeExactly 2 80 | $assertion[0].GetType().Name | Should -BeExactly 'Byte[]' 81 | $assertion[1].GetType().Name | Should -BeExactly 'Byte[]' 82 | } 83 | 84 | It -Name 'Outputs an array of arrays from the Pipeline' -Test { 85 | $assertion = $String, $String | ConvertFrom-StringToCompressedByteArray -Encoding $Encoding 86 | $assertion.Count | Should -BeExactly 2 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-StringToMemoryStream.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeAll { 12 | $String = 'ThisIsMyString' 13 | 14 | # Use the variables so IDe does not complain 15 | $null = $String 16 | } 17 | 18 | Context 'Input/Output' -Fixture { 19 | It -Name 'Converts a base64 encoded string to a MemoryStream Object' -Test { 20 | $assertion = ConvertFrom-StringToMemoryStream -String $String 21 | $assertion.GetType().Name | Should -BeExactly 'MemoryStream' 22 | } 23 | 24 | It -Name 'Returned a MemoryStream with the correct length' -Test { 25 | $assertion = ConvertFrom-StringToMemoryStream -String $String 26 | $assertion.Length | Should -BeExactly 14 27 | } 28 | 29 | It -Name 'Is a valid MemoryStream Object with the correct data' -Test { 30 | $memoryStream = ConvertFrom-StringToMemoryStream -String $String 31 | $reader = [System.IO.StreamReader]::new($memoryStream) 32 | $memoryStream.Position = 0 33 | 34 | $assertion = $reader.ReadToEnd() 35 | $assertion | Should -BeExactly $String 36 | } 37 | } 38 | 39 | Context -Name 'Pipeline' -Fixture { 40 | It -Name 'Supports the Pipeline' -Test { 41 | $assertion = $String | ConvertFrom-StringToMemoryStream 42 | $assertion.GetType().Name | Should -BeExactly 'MemoryStream' 43 | } 44 | 45 | It -Name 'Supports the Pipeline' -Test { 46 | $assertion = @($String, $String) | ConvertFrom-StringToMemoryStream 47 | $assertion | Should -HaveCount 2 48 | } 49 | } 50 | 51 | Context -Name 'Compressed stream' -Fixture { 52 | It -Name 'Returns a gzip compressed MemoryStream' -Test { 53 | $assertion = ConvertFrom-StringToMemoryStream -String $String -Compress 54 | $assertion.GetType().Name | Should -BeExactly 'MemoryStream' 55 | } 56 | 57 | It -Name 'Returned a MemoryStream that can still be read' -Test { 58 | $assertion = ConvertFrom-StringToMemoryStream -String $String -Compress 59 | $assertion.CanRead | Should -BeTrue 60 | } 61 | 62 | It -Name 'Returned a MemoryStream with the correct compressed length' -Test { 63 | $assertion = ConvertFrom-StringToMemoryStream -String $String -Compress 64 | $assertion.Length | Should -BeExactly 10 65 | } 66 | 67 | It -Name 'Compressed stream is shorter than the non-compressed stream' -Test { 68 | $testString = 'This string has multiple string values' 69 | $nonCompressed = ConvertFrom-StringToMemoryStream -String $testString 70 | $compressed = ConvertFrom-StringToMemoryStream -String $testString -Compress 71 | $compressed.Length | Should -BeLessThan $nonCompressed.Length 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertFrom-UnixTime.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $epochTime = Get-Date -Date '01-01-1970' 13 | 14 | # Use the variables so IDE does not complain 15 | $null = $epochTime 16 | } 17 | 18 | Context -Name 'Converts a date time represented as Unix time to a date time object' -Fixture { 19 | It -Name 'Supports a Unix time in seconds' -Test { 20 | $currentTime = [DateTime]::UtcNow 21 | $unixtime = [System.Math]::Round(($currentTime - $epochTime).TotalSeconds) 22 | $assertion = ConvertFrom-UnixTime -UnixTime $unixtime 23 | 24 | $assertion | Should -BeOfType [datetime] 25 | 26 | # As we cannot guarantee these values will be the same, we'll ensure they're within 1 seconds of each other 27 | ($currentTime - $assertion).TotalSeconds | Should -BeLessThan 1 28 | } 29 | 30 | It -Name 'Supports a Unix time in milliseconds' -Test { 31 | $currentTime = [DateTime]::UtcNow 32 | $unixtime = [System.Math]::Round(($currentTime - $epochTime).TotalMilliseconds) 33 | $assertion = ConvertFrom-UnixTime -UnixTime $unixtime -FromMilliseconds 34 | 35 | $assertion | Should -BeOfType [datetime] 36 | 37 | # As we cannot guarantee these values will be the same, we'll ensure they're within 1 seconds of each other 38 | ($currentTime - $assertion).TotalMilliseconds | Should -BeLessThan 1000 39 | } 40 | 41 | It -Name 'Supports the PowerShell Pipeline' -Test { 42 | $currentTime = [DateTime]::UtcNow 43 | $unixtime = [System.Math]::Round(($currentTime - $epochTime).TotalSeconds) 44 | $assertion = $unixtime | ConvertFrom-UnixTime 45 | 46 | $assertion | Should -BeOfType [datetime] 47 | 48 | # As we cannot guarantee these values will be the same, we'll ensure they're within 1 seconds of each other 49 | ($currentTime - $assertion).TotalSeconds | Should -BeLessThan 1 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertTo-Celsius.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe $function { 11 | Context 'Function usage' { 12 | It 'Converts °F to °C' -ForEach @( 13 | @{ Celsius = 0; Fahrenheit = 32 } 14 | @{ Celsius = 100; Fahrenheit = 212 } 15 | @{ Celsius = -40; Fahrenheit = -40 } 16 | ) { 17 | ConvertTo-Celsius -Fahrenheit $Fahrenheit | Should -Be $Celsius 18 | } 19 | 20 | It 'Handles pipeline input' { 21 | 68 | ConvertTo-Celsius | Should -Be 20 22 | } 23 | 24 | It 'Throws on absolute zero violation' { 25 | { ConvertTo-Celsius -Fahrenheit -460 } | Should -Throw 26 | } 27 | 28 | Context 'Rounds to 2 decimal places' { 29 | It 'Converts °F to °C' -ForEach @( 30 | @{ Celsius = 37.7; Fahrenheit = 99.86 } 31 | @{ Celsius = 37.77; Fahrenheit = 99.99 } 32 | @{ Celsius = 37.78; Fahrenheit = 99.999 } 33 | @{ Celsius = 37.78; Fahrenheit = 100 } 34 | ) { 35 | ConvertTo-Celsius -Fahrenheit $Fahrenheit | Should -Be $Celsius 36 | } 37 | } 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertTo-Clixml.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $String = 'ThisIsMyString' 13 | 14 | function GetException { 15 | try { 16 | throw 'blah' 17 | } catch { 18 | return $_ 19 | } 20 | } 21 | 22 | function GetExpected { 23 | param ($String) 24 | $filePath = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath 'clixml.txt' 25 | $String | Export-Clixml -Path $filePath 26 | return (Get-Content -Path $filePath -Raw) 27 | 28 | } 29 | 30 | # Use the variables so IDe does not complain 31 | $null = $String 32 | } 33 | 34 | Context -Name 'Input/Output' -Fixture { 35 | It -Name "Converts to Clixml correctly" -Test { 36 | $assertion = ConvertTo-Clixml -InputObject $String 37 | $assertion | Should -BeExactly (GetExpected -String $String) 38 | } 39 | } 40 | 41 | Context -Name 'Depth Support' -Fixture { 42 | BeforeEach { 43 | # Using an exception object as the object to test 44 | $TestObject = GetException 45 | 46 | $ExpectedDepth1File = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath 'Depth1.xml' 47 | $ExpectedDepth2File = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath 'Depth2.xml' 48 | 49 | $ExpectedDepth1File, $ExpectedDepth2File | Remove-Item -Force -ErrorAction SilentlyContinue 50 | 51 | $testObject | Export-Clixml -Depth 1 -Path $ExpectedDepth1File 52 | $testObject | Export-Clixml -Depth 2 -Path $ExpectedDepth2File 53 | 54 | $ExpectedDepth1 = Get-Content -Path $ExpectedDepth1File -Raw 55 | $ExpectedDepth2 = Get-Content -Path $ExpectedDepth2File -Raw 56 | 57 | $null = $ExpectedDepth1, $ExpectedDepth2 58 | } 59 | 60 | It -Name "Supports depth 1 by default" -Test { 61 | $assertionDepth1Default = ConvertTo-Clixml -InputObject $TestObject 62 | $assertionDepth1Default | Should -BeExactly $ExpectedDepth1 63 | } 64 | 65 | It -Name "Supports depth 1 when specified" -Test { 66 | $assertionDepth1 = ConvertTo-Clixml -InputObject $TestObject -Depth 1 67 | $assertionDepth1 | Should -BeExactly $ExpectedDepth1 68 | } 69 | 70 | It -Name "Supports depth 2 when specified" -Test { 71 | $assertionDepth2 = ConvertTo-Clixml -InputObject $TestObject -Depth 2 72 | $assertionDepth2 | Should -BeExactly $ExpectedDepth2 73 | } 74 | } 75 | 76 | Context -Name 'Pipeline' -Fixture { 77 | It -Name 'Supports the Pipeline' -Test { 78 | $assertion = $String | ConvertTo-Clixml 79 | $assertion | Should -BeExactly (GetExpected -String $String) 80 | } 81 | 82 | It -Name 'Supports the Pipeline with array input' -Test { 83 | $assertion = $String, $String | ConvertTo-Clixml 84 | $assertion | Should -HaveCount 2 85 | } 86 | } 87 | 88 | Context -Name 'Input/Output' -Fixture { 89 | It -Name "Converts to Clixml correctly" -Test { 90 | $assertion = ConvertTo-Clixml -InputObject $String 91 | $assertion | Should -BeExactly (GetExpected -String $String) 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertTo-EscapedUrl.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe $function { 11 | BeforeEach { 12 | $url = 'http://test.com?value=my #$%@`/:;<=>?[\]^{|}~"' + "'" + '+,value' 13 | $expected = $url.Replace('%', '%25') 14 | $expected = $expected.Replace(' ', '%20') 15 | $expected = $expected.Replace('#', '%23') 16 | $expected = $expected.Replace('$', '%24') 17 | $expected = $expected.Replace('&', '%26') 18 | $expected = $expected.Replace('@', '%40') 19 | $expected = $expected.Replace('`', '%60') 20 | $expected = $expected.Replace('/', '%2F') 21 | $expected = $expected.Replace(':', '%3A') 22 | $expected = $expected.Replace(';', '%3B') 23 | $expected = $expected.Replace('<', '%3C') 24 | $expected = $expected.Replace('=', '%3D') 25 | $expected = $expected.Replace('>', '%3E') 26 | $expected = $expected.Replace('?', '%3F') 27 | $expected = $expected.Replace('[', '%5B') 28 | $expected = $expected.Replace('\', '%5C') 29 | $expected = $expected.Replace(']', '%5D') 30 | $expected = $expected.Replace('^', '%5E') 31 | $expected = $expected.Replace('{', '%7B') 32 | $expected = $expected.Replace('|', '%7C') 33 | $expected = $expected.Replace('}', '%7D') 34 | $expected = $expected.Replace('~', '%7E') 35 | $expected = $expected.Replace('"', '%22') 36 | $expected = $expected.Replace("'", '%27') 37 | $expected = $expected.Replace('+', '%2B') 38 | $expected = $expected.Replace(',', '%2C') 39 | 40 | $null = $expected, $url 41 | } 42 | 43 | It 'Converts a URL to an escaped URL' { 44 | $assertion = ConvertTo-EscapedUrl -Url $url 45 | $assertion | Should -BeExactly $expected 46 | } 47 | 48 | It 'Supports the PowerShell pipeline' { 49 | $assertion = $url | ConvertTo-EscapedUrl 50 | $assertion | Should -BeExactly $expected 51 | } 52 | 53 | It 'Supports the PowerShell pipeline by value name' { 54 | $assertion = [PSCustomObject]@{Url = $url} | ConvertTo-EscapedUrl 55 | $assertion | Should -BeExactly $expected 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertTo-Fahrenheit.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe $function { 11 | Context 'Function usage' { 12 | It 'Converts °C to °F' -ForEach @( 13 | @{ Celsius = 0; Fahrenheit = 32 } 14 | @{ Celsius = 100; Fahrenheit = 212 } 15 | @{ Celsius = -40; Fahrenheit = -40 } 16 | ) { 17 | ConvertTo-Fahrenheit -Celsius $Celsius | Should -Be $Fahrenheit 18 | } 19 | 20 | It 'Handles pipeline input' { 21 | 20 | ConvertTo-Fahrenheit | Should -Be 68 22 | } 23 | 24 | It 'Throws on absolute zero violation' { 25 | { ConvertTo-Fahrenheit -Celsius -274 } | Should -Throw 26 | } 27 | 28 | Context 'Rounds to 2 decimal places' { 29 | It 'Converts °C to °F' -ForEach @( 30 | @{ Celsius = 37.7; Fahrenheit = 99.86 } 31 | @{ Celsius = 37.77; Fahrenheit = 99.99 } 32 | @{ Celsius = 37.777; Fahrenheit = 100 } 33 | @{ Celsius = 37.78; Fahrenheit = 100 } 34 | ) { 35 | ConvertTo-Fahrenheit -Celsius $Celsius | Should -Be $Fahrenheit 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertTo-Hash.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $string = 'ThisIsMyString' 13 | $sha256 = 'DBAF9836CA5BBF0644DCDE541D671239B45ACDB204536E0FB1CC842673B5D5D3' 14 | 15 | # Use the variables so IDe does not complain 16 | $null = $string, $sha256 17 | } 18 | 19 | Context -Name 'Supports different algorithms' -Fixture { 20 | It -Name '' -TestCases @( 21 | @{ 22 | Algorithm = 'MD5' 23 | Expected = '441BE86C39533902C582CB7C8BEB7CF4' 24 | } 25 | @{ 26 | Algorithm = 'SHA1' 27 | Expected = '6533C22836F0C1D1607519E505EAFEECFF3B5439' 28 | } 29 | @{ 30 | Algorithm = 'SHA256' 31 | Expected = 'DBAF9836CA5BBF0644DCDE541D671239B45ACDB204536E0FB1CC842673B5D5D3' 32 | } 33 | @{ 34 | Algorithm = 'SHA384' 35 | Expected = '33EC2F5D5888732993776B82DADE9030D4582C39CA5FC523207BF27E42CE6DC1449D9305EA757324B6FC9BA32E0847A6' 36 | } 37 | @{ 38 | Algorithm = 'SHA512' 39 | Expected = '4E9FAD2106AFD422B682D5A85C5E41340DAC2BB961C0E9BBFF040E79730EC0EBFD26A1A3AD6692C0BDE21D34814971588B9A908047CA2BA9ACE3E961DA13EF11' 40 | } 41 | ) -Test { 42 | $assertion = ConvertTo-Hash -String $String -Algorithm $Algorithm 43 | $assertion | Should -BeExactly $Expected 44 | } 45 | 46 | It -Name 'Converts from Pipeline' -Test { 47 | $assertion = $String | ConvertTo-Hash 48 | $assertion | Should -BeExactly $sha256 49 | } 50 | 51 | It -Name 'Converts an array from Pipeline' -Test { 52 | $assertion = $String, $String | ConvertTo-Hash 53 | 54 | $assertion | Should -HaveCount 2 55 | $assertion[0] | Should -BeExactly $sha256 56 | $assertion[1] | Should -BeExactly $sha256 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertTo-MemoryStream.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $String = 'ThisIsMyString' 13 | 14 | # Use the variables so IDe does not complain 15 | $null = $String 16 | } 17 | 18 | Context 'String input' -Fixture { 19 | It -Name 'Converts a string to a MemoryStream Object' -Test { 20 | $assertion = ConvertTo-MemoryStream -String $String 21 | $assertion.GetType().Name | Should -BeExactly 'MemoryStream' 22 | } 23 | 24 | It -Name 'Is a valid MemoryStream Object with the correct data' -Test { 25 | $memoryStream = ConvertTo-MemoryStream -String $String 26 | $reader = [System.IO.StreamReader]::new($memoryStream) 27 | $memoryStream.Position = 0 28 | 29 | $assertion = $reader.ReadToEnd() 30 | $assertion | Should -BeExactly $String 31 | } 32 | } 33 | 34 | Context -Name 'Pipeline' -Fixture { 35 | It -Name 'Supports the Pipeline' -Test { 36 | $assertion = $String | ConvertTo-MemoryStream 37 | $assertion.GetType().Name | Should -BeExactly 'MemoryStream' 38 | } 39 | 40 | It -Name 'Supports array Pipeline input' -Test { 41 | $assertion = @($String, $String) | ConvertTo-MemoryStream 42 | $assertion | Should -HaveCount 2 43 | } 44 | } 45 | 46 | Context -Name 'Compressed stream' -Fixture { 47 | It -Name 'Returns a gzip compressed MemoryStream' -Test { 48 | $assertion = ConvertTo-MemoryStream -String $String -Compress 49 | $assertion.GetType().Name | Should -BeExactly 'MemoryStream' 50 | } 51 | 52 | It -Name 'Returned a MemoryStream that can still be read' -Test { 53 | $assertion = ConvertTo-MemoryStream -String $String -Compress 54 | $assertion.CanRead | Should -BeTrue 55 | } 56 | 57 | It -Name 'Returned a MemoryStream with the correct compressed length' -Test { 58 | $assertion = ConvertTo-MemoryStream -String $String -Compress 59 | $assertion.Length | Should -BeExactly 10 60 | } 61 | 62 | It -Name 'Compressed stream is shorter than the non-compressed stream' -Test { 63 | $testString = 'This string has multiple string values' 64 | $nonCompressed = ConvertTo-MemoryStream -String $testString 65 | $compressed = ConvertTo-MemoryStream -String $testString -Compress 66 | $compressed.Length | Should -BeLessThan $nonCompressed.Length 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertTo-String.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $String = 'ThisIsMyString' 13 | 14 | # Use the variables so IDe does not complain 15 | $null = $String 16 | } 17 | 18 | Context -Name 'String input' -Fixture { 19 | It -Name 'Converts to base64 correctly' -Test { 20 | $base64 = 'VGhpc0lzTXlTdHJpbmc=' 21 | $assertion = ConvertTo-String -Base64EncodedString $base64 -Encoding UTF8 22 | 23 | $assertion | Should -BeExactly $String 24 | } 25 | 26 | It -Name 'Converts from Pipeline' -Test { 27 | $base64 = 'VGhpc0lzTXlTdHJpbmc=' 28 | $assertion = $base64 | ConvertTo-String -Encoding UTF8 29 | 30 | $assertion | Should -BeExactly $String 31 | } 32 | 33 | It -Name 'Converts an array from Pipeline' -Test { 34 | $base64 = 'VGhpc0lzTXlTdHJpbmc=' 35 | $assertion = $base64, $base64 | ConvertTo-String -Encoding UTF8 36 | 37 | $assertion | Should -HaveCount 2 38 | } 39 | 40 | It -Name 'Converts from compressed base64 string' -Test { 41 | $base64 = 'H4sIAAAAAAAEAAthyGDIZChm8ARiX4ZKhmCGEoYioEgeQzoDAC8A9r4cAAAA' 42 | $assertion = ConvertTo-String -Base64EncodedString $base64 -Encoding Unicode -Decompress 43 | 44 | $assertion | Should -BeExactly $String 45 | } 46 | } 47 | 48 | Context -Name 'MemoryStream input' -Fixture { 49 | It -Name 'Converts to base64 correctly' -Test { 50 | $stream = [System.IO.MemoryStream]::new() 51 | $writer = [System.IO.StreamWriter]::new($stream) 52 | $writer.Write($string) 53 | $writer.Flush() 54 | 55 | $assertion = ConvertTo-String -MemoryStream $stream 56 | 57 | $assertion | Should -BeExactly $String 58 | 59 | $stream.Dispose() 60 | $writer.Dispose() 61 | } 62 | 63 | It -Name 'Converts from Pipeline' -Test { 64 | $stream = [System.IO.MemoryStream]::new() 65 | $writer = [System.IO.StreamWriter]::new($stream) 66 | $writer.Write($string) 67 | $writer.Flush() 68 | 69 | $assertion = $stream | ConvertTo-String 70 | 71 | $assertion | Should -BeExactly $String 72 | 73 | $stream.Dispose() 74 | $writer.Dispose() 75 | } 76 | 77 | It -Name 'Converts an array from Pipeline' -Test { 78 | $stream = [System.IO.MemoryStream]::new() 79 | $writer = [System.IO.StreamWriter]::new($stream) 80 | $writer.Write($string) 81 | $writer.Flush() 82 | 83 | $stream2 = [System.IO.MemoryStream]::new() 84 | $writer2 = [System.IO.StreamWriter]::new($stream2) 85 | $writer2.Write($String) 86 | $writer2.Flush() 87 | 88 | $assertion = @($stream, $stream2) | ConvertTo-String 89 | 90 | $assertion | Should -HaveCount 2 91 | 92 | $stream.Dispose() 93 | $stream2.Dispose() 94 | $writer.Dispose() 95 | $writer2.Dispose() 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertTo-TitleCase.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe $function { 11 | It 'Converts to TitleCase correctly' { 12 | $string = 'this is a string' 13 | $expected = 'This Is A String' 14 | 15 | $assertion = ConvertTo-TitleCase -String $string 16 | $assertion | Should -BeExactly $expected 17 | } 18 | 19 | It 'Supports the PowerShell pipeline' { 20 | $strings = @('this is a string', 'another_string') 21 | $expected = @('This Is A String', 'Another_String') 22 | 23 | $assertion = $strings | ConvertTo-TitleCase 24 | $assertion | Should -BeExactly $expected 25 | } 26 | 27 | It 'Supports the PowerShell pipeline by value name' { 28 | $strings = @([PSCustomObject]@{ 29 | String = 'this is a string' 30 | }, [PSCustomObject]@{ 31 | String = 'another_string' 32 | }) 33 | $expected = @('This Is A String', 'Another_String') 34 | 35 | $assertion = $strings | ConvertTo-TitleCase 36 | $assertion | Should -BeExactly $expected 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Tests/Unit/ConvertTo-UnixTime.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $epochTime = Get-Date -Date '01-01-1970' 13 | 14 | # Use the variables so IDE does not complain 15 | $null = $epochTime 16 | } 17 | 18 | Context -Name 'By default, gets the current time represented as Unix time' -Fixture { 19 | It -Name 'Returns a Unix time in seconds' -Test { 20 | $now = [datetime]::UtcNow 21 | $currentUnixTime = [System.Math]::Round(($now - $epochTime).TotalSeconds) 22 | $assertion = ConvertTo-UnixTime -DateTime $now 23 | 24 | $assertion | Should -BeOfType [long] 25 | 26 | # As we cannot guarantee these values will be the same, we'll ensure they're within 1 seconds of each other 27 | $assertion - $currentUnixTime | Should -BeLessThan 1 28 | 29 | (($epochTime + [System.TimeSpan]::FromSeconds($assertion)) - $now).TotalSeconds | Should -BeLessThan 1 30 | } 31 | 32 | It -Name 'Returns a Unix time in milliseconds' -Test { 33 | $now = [datetime]::UtcNow 34 | $currentUnixTime = [System.Math]::Round(($now - $epochTime).TotalMilliseconds) 35 | $assertion = ConvertTo-UnixTime -DateTime $now -AsMilliseconds 36 | 37 | $assertion | Should -BeOfType [long] 38 | 39 | # As we cannot guarantee these values will be the same, we'll ensure they're within 1 seconds of each other 40 | $assertion - $currentUnixTime | Should -BeLessThan 1000 41 | (($epochTime + [System.TimeSpan]::FromMilliseconds($assertion)) - $now).TotalSeconds | Should -BeLessThan 1 42 | } 43 | } 44 | 45 | Context -Name 'Converts a date time to one represented as Unix time' -Fixture { 46 | It -Name 'Returns a Unix time in seconds' -Test { 47 | $datetime = (Get-Date).AddMonths(6) 48 | $currentUnixTime = [System.Math]::Round(($datetime - $epochTime).TotalSeconds) 49 | $assertion = ConvertTo-UnixTime -DateTime $datetime 50 | 51 | $assertion | Should -BeOfType [long] 52 | 53 | # As we cannot guarantee these values will be the same, we'll ensure they're within 1 seconds of each other 54 | $assertion - $currentUnixTime | Should -BeLessThan 1 55 | 56 | (($epochTime + [System.TimeSpan]::FromSeconds($assertion)) - $datetime).TotalSeconds | Should -BeLessThan 1 57 | } 58 | 59 | It -Name 'Returns a Unix time in milliseconds' -Test { 60 | $datetime = (Get-Date).AddMonths(6) 61 | $currentUnixTime = [System.Math]::Round(($datetime - $epochTime).TotalMilliseconds) 62 | $assertion = ConvertTo-UnixTime -DateTime $datetime -AsMilliseconds 63 | 64 | $assertion | Should -BeOfType [long] 65 | 66 | # As we cannot guarantee these values will be the same, we'll ensure they're within 1 seconds of each other 67 | $assertion - $currentUnixTime | Should -BeLessThan 1000 68 | (($epochTime + [System.TimeSpan]::FromMilliseconds($assertion)) - $datetime).TotalMilliseconds | Should -BeLessThan 1000 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Tests/Unit/Get-UnixTime.Tests.ps1: -------------------------------------------------------------------------------- 1 | $moduleName = 'Convert' 2 | $function = $MyInvocation.MyCommand.Name.Split('.')[0] 3 | 4 | $pathToManifest = [System.IO.Path]::Combine($PSScriptRoot, '..', '..', $moduleName, "$moduleName.psd1") 5 | if (Get-Module -Name $moduleName -ErrorAction 'SilentlyContinue') { 6 | Remove-Module -Name $moduleName -Force 7 | } 8 | Import-Module $pathToManifest -Force 9 | 10 | Describe -Name $function -Fixture { 11 | BeforeEach { 12 | $epochTime = Get-Date -Date '01-01-1970' 13 | 14 | # Use the variables so IDE does not complain 15 | $null = $epochTime 16 | } 17 | 18 | Context -Name 'Gets the current time represented as Unix time' -Fixture { 19 | It -Name 'Returns a Unix time in seconds' -Test { 20 | $now = [datetime]::UtcNow 21 | $currentUnixTime = [System.Math]::Round(($now - $epochTime).TotalSeconds) 22 | $assertion = Get-UnixTime 23 | 24 | $assertion | Should -BeOfType [long] 25 | 26 | # As we cannot guarantee these values will be the same, we'll ensure they're within 1 seconds of each other 27 | $assertion - $currentUnixTime | Should -BeLessThan 1 28 | 29 | (($epochTime + [System.TimeSpan]::FromSeconds($assertion)) - $now).TotalSeconds | Should -BeLessThan 1 30 | } 31 | 32 | It -Name 'Returns a Unix time in milliseconds' -Test { 33 | $now = [datetime]::UtcNow 34 | $currentUnixTime = [System.Math]::Round(($now - $epochTime).TotalMilliseconds) 35 | $assertion = Get-UnixTime -AsMilliseconds 36 | 37 | $assertion | Should -BeOfType [long] 38 | 39 | # As we cannot guarantee these values will be the same, we'll ensure they're within 1 seconds of each other 40 | $assertion - $currentUnixTime | Should -BeLessThan 1000 41 | (($epochTime + [System.TimeSpan]::FromMilliseconds($assertion)) - $now).TotalMilliseconds | Should -BeLessThan 1000 42 | } 43 | } 44 | } 45 | --------------------------------------------------------------------------------