Step 2: Create a Windows PowerShell Credentials Object
The credentials object provides a safe and secure way to pass your user name and password to Office 365. To create a credentials object, type the following command from the Windows PowerShell prompt and press ENTER:
$credential = Get-Credential
$credential is a variable that will store the credentials object. You don’t have to name the variable $credential, but doing so makes it easier to remember which variable contains the credentials object. (And that’s important, because we’ll reuse this variable several times.) That will also make it easier for you to follow our examples, because this article will always use $credential to represent the credentials object.
Windows PowerShell will then display a dialog box that looks like this:
Type your Office 365 user name in the User name box, using the format *username@domainname* (for example, firstname.lastname@example.org), then type your Office 365 password in the Password box and click OK:
Make sure the user account you specify has global administrator rights to Office 365. Otherwise your logon attempt will fail.
Note that, as is often the case, you won’t see any sort of confirmation that the credentials object was created. (Windows PowerShell typically tells you when things go wrong, but doesn’t always tell you when things go right.) If you want to verify that the credentials object was created, type the following at the Windows PowerShell prompt and then press ENTER:
You should then see something similar to this onscreen:
UserName Password -------- -------- email@example.com System.Security.SecureString
One thing to keep in mind here is that the Get-Credential cmdlet only creates the credentials object; it does not authenticate you or otherwise verify that the user name and password you supplied are correct. For example, suppose you mistyped the user name as firstname.lastname@example.org. If you do that, Get-Credential will create a credentials object using that user name, and without checking to see if that is actually a valid user name. You will not know whether you have created a truly valid credentials object until you actually use that object to try to connect to Office 365.
Speaking of which, that’s exactly where we are in our process: we’re ready to connect to Office 365.