Forum Discussion
TejCGS
Apr 25, 2019Copper Contributor
$cred = Get-Credential without asking for prompts in powershell
I am trying to run a script and i wanted to run it silently without asking for credential prompts. Is there a way to get around using "$cred = Get-Credential" without a prompt The script i am t...
- Apr 26, 2019
I have corrected your script (removed the unwanted call of Get-Credential and fixed the variable name creds)
$username = "admin@domain.com"
$password = ConvertTo-SecureString "mypassword" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $password)
Import-Module MSOnline
Connect-MSolService -Credential $psCred
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell-liveid/ -Credential $psCred -Authentication Basic -AllowRedirection
Import-PSSession $Session -AllowClobber -DisableNameChecking
BenStegink
Apr 25, 2019Iron Contributor
You can store passwords in an encrypted file on the machine you are running the script on. Here is a site that gives some examples - https://blog.kloud.com.au/2016/04/21/using-saved-credentials-securely-in-powershell-scripts/
You can also leverage windows credential manager to store credentials and retrieve the crowds from there in your script - https://bitsofwater.com/2018/02/16/using-credential-manager-in-powershell/
You can also leverage windows credential manager to store credentials and retrieve the crowds from there in your script - https://bitsofwater.com/2018/02/16/using-credential-manager-in-powershell/
meeoun
Sep 01, 2021Copper Contributor
With all due respect. Its not a question on best practice. I myself needed this for development stuff, a zone where I disable all security so that it is never in the way.