Share via


A Quick Note Regarding Positional Parameters and Office 365

 

Summary: Use Windows PowerShell to Manage Office 365 using Windows PowerShell cmdlets, scripts, and batch processes.

The Azure Active Directory cmdlets are different than the Exchange and Lync Online cmdlets, at least when it comes to working with individual user accounts. For example, with Lync Online and the Get-CsOnlineUser cmdlet, you can include the Identity parameter in your command or you can leave out the Identity parameter. In other words, these two commands both work, and they both return the exact same information:

Get-CsOnlineUser -Identity "kenmyer@litwareinc.onmicrosoft.com"
Get-CsOnlineUser "kenmyer@litwareinc.onmicrosoft.com"

But that’s not true for the Azure Active Directory cmdlets. This command works:

Get-MsolUser -UserPrincipalName "kenmyer@litwareinc.onmicrosoft.com"

Note

We used the UserPrincipalName parameter here because Get-MsolUser doesn’t have an Identity parameter.

But this command does not work:

Get-MsolUser "kenmyer@litwareinc.onmicrosoft.com"

Why not? Without going into a lot of technical detail, many of the Lync Online and the Exchange cmdlets configure the Identity parameter as a “positional parameter.” That means that (in these cases, anyway), if you don’t specify a parameter name (like –Identity) the cmdlet assumes that the very first parameter in the command is the Identity parameter. As long as you start off by specifying the user identity, you can either use the –Identity parameter or not use it. Either way works:

Get-CsOnlineUser -Identity "kenmyer@litwareinc.onmicrosoft.com"
Get-CsOnlineUser "kenmyer@litwareinc.onmicrosoft.com"

The Azure Active Directory cmdlets don’t support positional parameters, however. Suppose you include a value without an accompanying parameter:

Get-MsolUser "kenmyer@litwareinc.onmicrosoft.com"

In that case, you’ll get an error message like this one:

Get-MsolUser : A positional parameter cannot be found that accepts argument 'kenmyer@litwareinc.onmicrosoft.com'.

Note, too that Exchange and Lync Online let you refer to users in several different ways. For example, all of these Exchange commands return the same mailbox information:

Get-Mailbox -Identity "Ken Myer"
Get-Mailbox -Identity "kenmyer@litwareinc.onmicrosoft.com"
Get-Mailbox -Identity "kenmyer"

Those commands use the user’s Active Directory display name; his or her user principal name; and his or her email alias, respectively. Any one of those Identities will work. But that’s with Exchange, and with Lync Online. For the most part, Azure Active Directory requires you to use the use principal name and only the user principal name:

Get-MsolUser -UserPrincipalName "kenmyer@litwareinc.onmicrosoft.com"

Note

Well, technically, you can use the ObjectId parameter. But that requires you to enter the GUID (globally unique identifier) assigned to the user account. For example:
Get-MsolUser –ObjectId "62e90394-69f5-4237-9190-012177145e10"
We’ll let you decide for yourself whether to use UserPrincipalName or ObjectId.

Admittedly, that might be a lot to absorb, at least for someone new to Windows PowerShell. If you are new to Windows PowerShell you might want to take a look at our introductory article on working with parameters.

Next: Using Windows PowerShell to Manage SharePoint Online

See Also

Using Windows Azure Active Directory to Manage Office 365