Module/Misc/Get-BCSSecureString.ps1

<#
.SYNOPSIS
    Get a securestring from a text
.DESCRIPTION
    Creates a secure string based on a input text
     
.PARAMETER InputString
  The string in plain text
.PARAMETER AsPlainText
  Return the secure string as a text
 
.NOTES
    Author: Mathias Stjernfelt
    Website: http://www.brightcom.se
 
.EXAMPLE
    Get-BCSSecureString mySecureString
.EXAMPLE
    Get-BCSSecureString mySecureString -AsPlainText
#>

function Get-BCSSecureString {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
    Param(
        [Parameter(Mandatory = $true)]
        [String] $InputString,
        [Parameter(Mandatory = $false)]
        [switch] $AsPlainText = $false

    )

    if ($AsPlainText) {
        ConvertTo-SecureString -String $InputString -AsPlainText -Force | ConvertFrom-SecureString
    }
    else {
        ConvertTo-SecureString -String $InputString -AsPlainText -Force
    }
}

Export-ModuleMember -Function Get-BCSSecureString