|
1 | 1 | --- |
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." |
| 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." |
4 | 4 | categories: |
5 | 5 | - PowerShell |
6 | | - - Exchange |
7 | | - - Office 365 |
| 6 | + - Howto |
8 | 7 |
|
9 | 8 | tags: |
10 | 9 | - PowerShell |
11 | | - - Office365 |
12 | | - - Exchange |
| 10 | + - Tips |
| 11 | + - HowTo |
13 | 12 |
|
14 | 13 | toc: true |
15 | 14 | header: |
16 | 15 | teaser: "/assets/images/PowerShell_Logo.png" |
17 | 16 | --- |
18 | 17 |
|
19 | | -## Exchange Online Certificate Based authentication |
| 18 | +## PowerShell Get current date |
20 | 19 |
|
21 | | -Microsoft is, _finally_, disabling **basic authentication** (read username and password) in Exchange Online in favor of **Certificate Based authentication**. |
| 20 | +PowerShell natively supports getting the current, or specific, date via the following cmdlet: |
22 | 21 |
|
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. |
24 | | - |
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/). |
26 | | - |
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. |
28 | | - |
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 |
32 | | - |
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. |
| 22 | +```powershell |
| 23 | +Get-Date |
| 24 | +``` |
| 25 | +Which, by default, will produce the following output: |
34 | 26 |
|
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. |
| 27 | +```powershell |
| 28 | +Monday, February 21, 2022 10:11:39 PM |
| 29 | +``` |
36 | 30 |
|
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 |
| 31 | +Cmdlet supports methods which can be used to display/return the day of the week for the selected date |
38 | 32 |
|
39 | 33 | ```powershell |
40 | | -# Cmdlet I was running |
41 | | -Get-RemoteMailbox -Identity $userUpn |
42 | | -
|
43 | | -# Part of the exception message |
44 | | -Cannot bind argument to parameter 'token expiry time' because it is null. |
| 34 | +(Get-Date).DayOfWeek |
45 | 35 | ``` |
46 | 36 |
|
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. |
| 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 |
48 | 38 |
|
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} |
| 39 | +```powershell |
| 40 | +(Get-Date).DayOfWeek.value__ |
53 | 41 |
|
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. |
| 42 | +# Output |
| 43 | +1 |
| 44 | +``` |
56 | 45 |
|
57 | | -As soon as I have any news I will update the post until then I hope you can find the information useful. |
| 46 | +This is specially handy when inserting data into SQL datbase supporting dates as *TinyInt* data types. |
0 commit comments