Public/Set-EnvCredentials.ps1
function Set-EnvCredentials { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$usernameEnvName, [Parameter(Mandatory = $true)] [string]$passwordEnvName ) $username = [Environment]::GetEnvironmentVariable($usernameEnvName) $password = [Environment]::GetEnvironmentVariable($passwordEnvName) # Convert password to secure string $secpass = ConvertTo-SecureString $password -AsPlainText -Force # Create PSCredential object $cred = New-Object System.Management.Automation.PSCredential ($userName, $secpass) return $cred } |