function Set-LocalUserCredential { <# .SYNOPSIS Set the user's credentials in local environment variables This is mostly useful as a Profile line such as: `$creds = (Get-CredentialFromEnvironmentVariables) This way a developer can test faster with stored credentials without having to recreate them frequently #> param ( [Parameter(Mandatory=$false)] [Alias('Password')] $InputObject, [Parameter(Mandatory=$false)] [Alias('Username')] $User ) $logLead = (Get-LogLeadName) $secureString = $null if (![string]::IsNullOrWhiteSpace($InputObject)) { $secureString = (ConvertTo-SecureString $InputObject -AsPlainText -Force) } else { $secureString = (Read-Host -Prompt "Please provide a password" -AsSecureString) } if ([string]::IsNullOrWhiteSpace($User)) { $User = (whoami) } Write-Host "$logLead : Storing credentials for User [$User] in EnvironmentVariables in the User store" Set-EnvironmentVariable -Name "CREDENTIAL_USERNAME" -Store User -Value $User Set-EnvironmentVariable -Name "CREDENTIAL_LASTCHANGED" -Store User -Value ([System.DateTime]::Now.ToString()) Set-EnvironmentVariable -Name "CREDENTIAL_PASSWORD" -Store User -Value (ConvertFrom-SecureString $secureString) }