|
1 | 1 | --- |
2 | | -title: "PowerShell - Get day of weekday" |
3 | | -excerpt: "In this short post we will see how we can use PowerShell to get an integer representing the number associated with the day of the week for the current date." |
| 2 | +title: "Cannot bind argument to parameter TokenExpiryTime because it is null - Error Message" |
| 3 | +excerpt: "When opening a PowerShell session to both on-prem and Exchange online in the same window cannot bing argument to parameter TokenExpiryTime because is null error message could be displayed. Let's explore how to solve this." |
4 | 4 | categories: |
5 | 5 | - PowerShell |
6 | | - - Howto |
| 6 | + - Exchange |
| 7 | + - Office 365 |
7 | 8 |
|
8 | 9 | tags: |
9 | 10 | - PowerShell |
10 | | - - Tips |
11 | | - - HowTo |
| 11 | + - Office365 |
| 12 | + - Exchange |
12 | 13 |
|
13 | 14 | toc: true |
14 | 15 | header: |
15 | 16 | teaser: "/assets/images/PowerShell_Logo.png" |
16 | 17 | --- |
17 | 18 |
|
18 | | -## PowerShell Get current date |
| 19 | +## Exchange Online Certificate Based authentication |
19 | 20 |
|
20 | | -PowerShell natively supports getting the current, or specific, date via the following cmdlet: |
| 21 | +Microsoft is, _finally_, disabling **basic authentication** (read username and password) in Exchange Online in favor of **Certificate Based authentication**. |
21 | 22 |
|
22 | | -```powershell |
23 | | -Get-Date |
24 | | -``` |
25 | | -Which, by default, will produce the following output: |
| 23 | +Once this change is fully implemented, around mid February at least for some tenants, connecting via username and passwords to Exchange Online will not be possible anymore. |
26 | 24 |
|
27 | | -```powershell |
28 | | -Monday, February 21, 2022 10:11:39 PM |
29 | | -``` |
| 25 | +You can read my article on how to implement _Certificate Based authentication_ for Exchange Online [here](https://pscustomobject.github.io/powershell/office365/exchange/Exchange-Online-Certificate-Based-Authentication/). |
30 | 26 |
|
31 | | -Cmdlet supports methods which can be used to display/return the day of the week for the selected date |
| 27 | +As a result of this change I started updating one of our automations, responsible for the whole life-cycle of our mailboxes, to ditch old credential objects in favor of the more secure Certificate Authentication. |
32 | 28 |
|
33 | | -```powershell |
34 | | -(Get-Date).DayOfWeek |
35 | | -``` |
| 29 | +This is when I encountered the _cannot bind argument to parameter 'token expiry time' because it is null._ error message. |
| 30 | + |
| 31 | +## Multiple PowerShell Exchange Sessions |
36 | 32 |
|
37 | | -There are situations where rather than returning a string with the day name it can be useful to return the **number** (1 to 7) associated with the day's name, this can easily be accomplished with the following command |
| 33 | +When operating an hybrid environment it is pretty common to open, in the same window/session, a PowerShell connection to both Exchange on-prem and Exchange Online. |
| 34 | + |
| 35 | +This is required as part of the configuration, usually creation of the mailbox, takes place in on-prem for example via the _New-RemoteMailbox_ cmdlet while other parts of the configuration are performed directly online for example when delegating mailbox permissions. |
| 36 | + |
| 37 | +While debugging my workflow I have noticed that, while trying to retreive mailbox information from the on-prem server, an exception was being thrown |
38 | 38 |
|
39 | 39 | ```powershell |
40 | | -(Get-Date).DayOfWeek.value__ |
| 40 | +# Cmdlet I was running |
| 41 | +Get-RemoteMailbox -Identity $userUpn |
41 | 42 |
|
42 | | -# Output |
43 | | -1 |
| 43 | +# Part of the exception message |
| 44 | +Cannot bind argument to parameter 'token expiry time' because it is null. |
44 | 45 | ``` |
45 | 46 |
|
46 | | -This is specially handy when inserting data into SQL datbase supporting dates as *TinyInt* data types. |
| 47 | +It took me a bit to figure this out as no exception was thrown during the connection *phase* either nor there was any other obvious pointer. |
| 48 | + |
| 49 | +When I was about to give up and open a ticket with Microsoft, which is usually as helpful as freezer in the North Pole, I discovered that establishing a connection to Exchange Online followed by a connection to the on-prem server was yielding the desired result. In my workflow I had this the other way around, first local Exchange and then Online service, which was causing the issue. |
| 50 | + |
| 51 | +**Note:** I have experienced/tested this with version 2.0.4 and 2.0.5 of Exchange Online PowerShell module but other versions could be affected as well. |
| 52 | +{: .notice--warning} |
| 53 | + |
| 54 | +I did not dig deep into the root cause of the issue but plan to do this tomorrow and already sent my feedback to exocmdletpreview {at} service {dot} microsoft {dot} com but I doubt I will hear anything from that channel. |
| 55 | +I will anyhow open a ticket with support to at least have an official statement/clarification on this. |
| 56 | + |
| 57 | +As soon as I have any news I will update the post until then I hope you can find the information useful. |
0 commit comments