The PowerShell command Get-Credential is used to collect user credentials.


When I try to connect to Office 365 I’m suing this dialog to collect the login details of a user. I find it however very annoying that I have to keep supplying the user’s name and password. Ok, password is fine but the username is annoying especially with the long Office 365 logins ( …

When I looked at the options for Get-Credential I noticed -Username. This is a great option as I can now do something like:

[code lang=text]
Get-Credential -UserName “”

But no, still an empty login window.


Then I tried the -Message option. Why would this possibly be relevant???

[code lang=text]
Get-Credential -Message “Supply password” -UserName “”


The username is now set and I can type in my password. Well that saves be some time during the development of my PowerShell scripts.

Now a little check around the code and I only need to sign in once:

[code lang=text]
if ( $cred -ne $null)
$cred = Get-Credential -Message “Supply password” -UserName “”
Connect-SPOnline -Url “https:/ /” -Credentials $cred

Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as a Principal Architect at HybrIT Services Ltd. You can contact me using

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue Reading

%d bloggers like this: