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
Kevin_Morgan
Iron Contributor
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
Deb Codding
Jun 17, 2020Brass Contributor
Kevin_Morgan Thanks so much for your answer. Saved me a lot of time wading through useless information!