Connect-ExchangeOnline Secure Application Model set Culture

Borut Puhar 66 Reputation points
2021-01-04T09:35:23.897+00:00

Hi,
I have setup »Secure Application Model« to connect o Exchange online for my automation scripts.
Issue that I have is Culture. Im running under “CultureInfo de-DE” but return is En-US. This has an issue with retuned date time format with generic error “Invalid datetime value for property”. I solved this issue setting Set-Culture -CultureInfo En-US.
Question is, if there is workaround to set Culture when connecting to exchanger online with app model. Because this will effect other automation scripts, that run on system.

Thank you,
Borut

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,197 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Borut Puhar 66 Reputation points
    2021-01-05T10:17:09.433+00:00

    Hi,
    For example :
    Get-EXOMailboxFolderStatistics *****************

    Default : Set-Culture -CultureInfo de-DE <- This is my default local language setting

    WARNING: Invalid datetime value for property CreationTime. Value= 11/25/2019 9:29:51 AM.
    WARNING: Invalid datetime value for property LastModifiedTime. Value= 12/23/2020 7:12:59 AM.
    Name : Calendar
    SearchFolder : False
    CreationTime :
    LastModifiedTime :
    FolderPath : /Calendar

    WARNING: Invalid datetime value for property CreationTime. Value= 11/25/2019 9:29:51 AM.
    Name : Contacts
    SearchFolder : False
    CreationTime : <- 25/11/2019 woud be correct
    LastModifiedTime : 01.04.2021 20:13:05 **<- wrong 1.April. / 4. Januar **
    FolderPath : /Contacts

    No WARNING <- both are wrong for En-US
    Name : BIG
    SearchFolder : False
    CreationTime : 08.02.2020 17:34:14 <-this is 8th of Feb not 2th of Aug.
    LastModifiedTime : 01.05.2021 00:34:01
    FolderPath : /Inbox/BIG

    Now change to Set-Culture -CultureInfo En-US

    Name : Calendar
    SearchFolder : False
    CreationTime : 11/25/2019 9:29:51 AM
    LastModifiedTime : 12/23/2020 7:12:59 AM
    FolderPath : /Calendar

    Name : Contacts
    SearchFolder : False
    CreationTime : 11/25/2019 9:29:51 AM
    LastModifiedTime : 1/4/2021 8:13:05 PM
    FolderPath : /Contacts

    Name : BIG
    SearchFolder : False
    CreationTime : 8/2/2020 5:34:14 PM
    LastModifiedTime : 1/5/2021 12:34:01 AM
    FolderPath : /Inbox/BIG


  2. olavrb 131 Reputation points
    2021-01-13T10:12:37.1+00:00

    @Borut Puhar

    Could you say how you got ExchangeOnlineManagement to connect using Secure Application Model? I've made it work with the v2 module, but not the ExchangeOnlineManagement module yet.

    # Get access token  
    $CustomerExToken = New-PartnerAccessToken -Tenant $CustomerInitialDomain -ApplicationId $RefreshTokenIdentifier -RefreshToken $RefreshToken -Scopes 'https://outlook.office365.com/.default'  
    $CustomerCredential = [PSCredential]::new(  
      $CustomerExToken.'Account'.'Username',  
      $(ConvertTo-SecureString -String ('Bearer {0}' -f ($CustomerExToken.'AccessToken')) -AsPlainText -Force)  
    )  
              
    # Connect  
    $PSSession = New-PSSession -ConfigurationName 'Microsoft.Exchange' -ConnectionUri ('https://ps.outlook.com/powershell-liveid?DelegatedOrg={0}&amp;BasicAuthToOAuthConversion=true' -f ($CustomerExToken.'TenantId')) -Credential $CustomerCredential -Authentication 'Basic' -AllowRedirection -WarningAction 'SilentlyContinue'  
      
    # Import modules - Enter-PSSession if $RunFromOnprem      
    $null = Import-PSSession $PSSession -DisableNameChecking -ErrorAction 'Stop'  
    

    Edit:

    So we must use certificates? But I don't want to..

    0 comments No comments