PrivateFunctions/Get-Puppeteer_DeclareUsernameAndPassword.ps1
<#
.SYNOPSIS This function returns the Node JS Puppeteer code for declaring username and password variables. #> function Get-Puppeteer_DeclareUsernameAndPassword { [CmdletBinding(PositionalBinding=$true)] [OutputType([String])] param ( # The username. [Parameter(Mandatory=$true, ParameterSetName="usernamePassword")] [ValidateNotNullOrEmpty()] [String]$username, # The password. [Parameter(Mandatory=$true, ParameterSetName="usernamePassword")] [ValidateNotNull()] [SecureString]$password, # The credential containing the username and the password. [Parameter(Mandatory=$true, ParameterSetName="credential")] [ValidateNotNull()] [PSCredential]$credential ) # Create a credential object if ($PSCmdlet.ParameterSetName -eq "usernamePassword") { $credential = New-Object System.Management.Automation.PSCredential $username $password } # Generate the code $code = @" const username = "%username%"; const password = "%password%"; "@ $code = $code -replace "%username%", $credential.Username $code = $code -replace "%password%", $credential.GetNetworkCredential().Password # Return the code return $code } |