grahamr975 / EWS-Office365-Contact-Sync

Uses Exchange Web Services to synchronize a Global Address List in Office 365 to a user's mailbox
MIT License
94 stars 21 forks source link

Requesting Support for EWS-Office365-Contact-Sync Script #85

Open sbakkerlukkien opened 1 year ago

sbakkerlukkien commented 1 year ago

Dear @grahamr975,

I hope this message finds you well. I am writing to seek assistance with an issue I encountered while using the "EWS-Office365-Contact-Sync" script. I have provided a transcript of the error below:


Windows PowerShell transcript start Start time: 20230614153710 Username: LUKKIEN0\p.xxx RunAs User: LUKKIEN0\p.xxx Configuration Name: Machine: DESKTOP-XXXXX (Microsoft Windows NT 10.0.19044.0) Host Application: PowerShell.exe -ExecutionPolicy Bypass -File C:\EWS-Office365-Contact-Sync\EWSContactSync.ps1 -CertificatePath C:\Users\p.xxx\cert\mycert.pfx -CertificatePasswordPath C:\Users\p.xxx\Desktop\credentials.cred -ClientID bd0aeb2e-xxxx-xxx-993f-09d9215ee214 -FolderName LukNumbers -LogPath C:\EWS-Office365-Contact-Sync\Logs -MailboxList j.doe@lukxxx.com -ExchangeOrg lukkxxxxxx.onmicrosoft.com -ModernAuth Process ID: 7872 PSVersion: 5.1.19041.2673 PSEdition: Desktop PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.19041.2673 BuildVersion: 10.0.19041.2673 CLRVersion: 4.0.30319.42000 WSManStackVersion: 3.0 PSRemotingProtocolVersion: 2.3 SerializationVersion: 1.1.0.1


Transcript started, output file is C:\EWS-Office365-Contact-Sync\Logs\PowerShelltranscript.DESKTOP-XXXXX.ICDAVgz.20230614153710.txt VERBOSE: Loading module from path 'C:\EWS-Office365-Contact-Sync\EWSContacts\Module\ExchangeContacts.psm1'. VERBOSE: Exporting function 'Import-ModuleFile'. VERBOSE: Exporting function 'Find-CCNumber'. VERBOSE: Exporting function 'Get-AutoDiscoverPhotoURL'. VERBOSE: Exporting function 'Get-NumbersInString'. VERBOSE: Exporting function 'Get-PublicFolderIdFromPath'. VERBOSE: Exporting function 'Get-UniqueFileName'. VERBOSE: Exporting function 'Get-UserDN'. VERBOSE: Exporting function 'Set-PublicFolderContentRoutingHeader'. VERBOSE: Exporting function 'Set-PublicFolderRoutingHeader'. VERBOSE: Exporting function 'Test-EmailAddress'. VERBOSE: Exporting function 'Write-Log'. VERBOSE: Exporting function 'Get-EXCContactGroup'. VERBOSE: Exporting function 'Get-EXCContactGroups'. VERBOSE: Exporting function 'New-EXCContactGroup'. VERBOSE: Exporting function 'Search-EXCAllContactGroups'. VERBOSE: Exporting function 'ConvertToString'. VERBOSE: Exporting function 'Get-EmailAddressFromContact'. VERBOSE: Exporting function 'Get-EXCContact'. VERBOSE: Exporting function 'Get-EXCContacts'. VERBOSE: Exporting function 'Get-EXCContactsObject'. VERBOSE: Exporting function 'Get-GALContacts'. VERBOSE: Exporting function 'Get-Mailboxes'. VERBOSE: Exporting function 'New-EXCContact'. VERBOSE: Exporting function 'New-EXCContactObject'. VERBOSE: Exporting function 'Remove-EXCContact'. VERBOSE: Exporting function 'Set-EXCContact'. VERBOSE: Exporting function 'Set-EXCContactObject'. VERBOSE: Exporting function 'Sync-ContactList'. VERBOSE: Exporting function 'Export-EXCContactFolder'. VERBOSE: Exporting function 'Get-EXCAllContactFolders'. VERBOSE: Exporting function 'Get-EXCContactFolder'. VERBOSE: Exporting function 'New-EXCContactFolder'. VERBOSE: Exporting function 'Connect-EXCExchange'. VERBOSE: Importing function 'Connect-EXCExchange'. VERBOSE: Importing function 'ConvertToString'. VERBOSE: Importing function 'Export-EXCContactFolder'. VERBOSE: Importing function 'Find-CCNumber'. VERBOSE: Importing function 'Get-AutoDiscoverPhotoURL'. VERBOSE: Importing function 'Get-EmailAddressFromContact'. VERBOSE: Importing function 'Get-EXCAllContactFolders'. VERBOSE: Importing function 'Get-EXCContact'. VERBOSE: Importing function 'Get-EXCContactFolder'. VERBOSE: Importing function 'Get-EXCContactGroup'. VERBOSE: Importing function 'Get-EXCContactGroups'. VERBOSE: Importing function 'Get-EXCContacts'. VERBOSE: Importing function 'Get-EXCContactsObject'. VERBOSE: Importing function 'Get-GALContacts'. VERBOSE: Importing function 'Get-Mailboxes'. VERBOSE: Importing function 'Get-NumbersInString'. VERBOSE: Importing function 'Get-PublicFolderIdFromPath'. VERBOSE: Importing function 'Get-UniqueFileName'. VERBOSE: Importing function 'Get-UserDN'. VERBOSE: Importing function 'Import-ModuleFile'. VERBOSE: Importing function 'New-EXCContact'. VERBOSE: Importing function 'New-EXCContactFolder'. VERBOSE: Importing function 'New-EXCContactGroup'. VERBOSE: Importing function 'New-EXCContactObject'. VERBOSE: Importing function 'Remove-EXCContact'. VERBOSE: Importing function 'Search-EXCAllContactGroups'. VERBOSE: Importing function 'Set-EXCContact'. VERBOSE: Importing function 'Set-EXCContactObject'. VERBOSE: Importing function 'Set-PublicFolderContentRoutingHeader'. VERBOSE: Importing function 'Set-PublicFolderRoutingHeader'. VERBOSE: Importing function 'Sync-ContactList'. VERBOSE: Importing function 'Test-EmailAddress'. VERBOSE: Importing function 'Write-Log'. VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.5\ExchangeOnlineManagement.psd1'. VERBOSE: Populating RepositorySourceLocation property for module ExchangeOnlineManagement. VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.5.\netFramework\ExchangeOnlineManagement.psm1'. VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.5\netFramework\Microsoft.Exchange.Management.RestApiClient.dll'. VERBOSE: Importing cmdlet 'Get-EXOCasMailbox'. VERBOSE: Importing cmdlet 'Get-EXOMailbox'. VERBOSE: Importing cmdlet 'Get-EXOMailboxFolderPermission'. VERBOSE: Importing cmdlet 'Get-EXOMailboxFolderStatistics'. VERBOSE: Importing cmdlet 'Get-EXOMailboxPermission'. VERBOSE: Importing cmdlet 'Get-EXOMailboxStatistics'. VERBOSE: Importing cmdlet 'Get-EXOMobileDeviceStatistics'. VERBOSE: Importing cmdlet 'Get-EXORecipient'. VERBOSE: Importing cmdlet 'Get-EXORecipientPermission'. VERBOSE: Importing cmdlet 'Set-ExoAppSettings'. VERBOSE: Importing cmdlet 'Set-EXOCasMailbox'. VERBOSE: Importing cmdlet 'Set-EXOMailbox'. VERBOSE: Importing cmdlet 'Get-VivaInsightsSettings'. VERBOSE: Importing cmdlet 'Set-VivaInsightsSettings'. VERBOSE: Importing cmdlet 'Get-OwnerlessGroupPolicy'. VERBOSE: Importing cmdlet 'Set-OwnerlessGroupPolicy'. VERBOSE: Importing cmdlet 'Set-MyAnalyticsFeatureConfig'. VERBOSE: Importing cmdlet 'Get-MyAnalyticsFeatureConfig'. VERBOSE: Importing cmdlet 'Get-UserBriefingConfig'. VERBOSE: Importing cmdlet 'Set-UserBriefingConfig'. VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.5\netFramework\Microsoft.Exchange.Management.ExoPowershellGalleryModule.dll'. VERBOSE: Importing cmdlet 'Add-EXOClientTelemetryWrapper'. VERBOSE: Importing cmdlet 'New-EXOClientTelemetryFilepath'. VERBOSE: Importing cmdlet 'Push-EXOTelemetryRecord'. VERBOSE: Importing cmdlet 'Clear-ActiveToken'. VERBOSE: Importing cmdlet 'New-ExoPSSession'. VERBOSE: Importing cmdlet 'Test-ActiveToken'. VERBOSE: Exporting function 'Print-Details'. VERBOSE: Exporting function 'Test-Uri'. VERBOSE: Exporting function 'Get-OrgNameFromUPN'. VERBOSE: Exporting function 'Connect-ExchangeOnline'. VERBOSE: Exporting function 'Connect-IPPSSession'. VERBOSE: Exporting function 'Disconnect-ExchangeOnline'. VERBOSE: Exporting cmdlet 'Get-EXOCasMailbox'. VERBOSE: Exporting cmdlet 'Get-EXOMailbox'. VERBOSE: Exporting cmdlet 'Get-EXOMailboxFolderPermission'. VERBOSE: Exporting cmdlet 'Get-EXOMailboxFolderStatistics'. VERBOSE: Exporting cmdlet 'Get-EXOMailboxPermission'. VERBOSE: Exporting cmdlet 'Get-EXOMailboxStatistics'. VERBOSE: Exporting cmdlet 'Get-EXOMobileDeviceStatistics'. VERBOSE: Exporting cmdlet 'Get-EXORecipient'. VERBOSE: Exporting cmdlet 'Get-EXORecipientPermission'. VERBOSE: Exporting cmdlet 'Set-ExoAppSettings'. VERBOSE: Exporting cmdlet 'Set-EXOCasMailbox'. VERBOSE: Exporting cmdlet 'Set-EXOMailbox'. VERBOSE: Exporting cmdlet 'Get-VivaInsightsSettings'. VERBOSE: Exporting cmdlet 'Set-VivaInsightsSettings'. VERBOSE: Exporting cmdlet 'Get-OwnerlessGroupPolicy'. VERBOSE: Exporting cmdlet 'Set-OwnerlessGroupPolicy'. VERBOSE: Exporting cmdlet 'Set-MyAnalyticsFeatureConfig'. VERBOSE: Exporting cmdlet 'Get-MyAnalyticsFeatureConfig'. VERBOSE: Exporting cmdlet 'Get-UserBriefingConfig'. VERBOSE: Exporting cmdlet 'Set-UserBriefingConfig'. VERBOSE: Exporting cmdlet 'Add-EXOClientTelemetryWrapper'. VERBOSE: Exporting cmdlet 'New-EXOClientTelemetryFilepath'. VERBOSE: Exporting cmdlet 'Push-EXOTelemetryRecord'. VERBOSE: Exporting cmdlet 'Clear-ActiveToken'. VERBOSE: Exporting cmdlet 'New-ExoPSSession'. VERBOSE: Exporting cmdlet 'Test-ActiveToken'. VERBOSE: Importing cmdlet 'Get-EXOCasMailbox'. VERBOSE: Importing cmdlet 'Get-EXOMailbox'. VERBOSE: Importing cmdlet 'Get-EXOMailboxFolderPermission'. VERBOSE: Importing cmdlet 'Get-EXOMailboxFolderStatistics'. VERBOSE: Importing cmdlet 'Get-EXOMailboxPermission'. VERBOSE: Importing cmdlet 'Get-EXOMailboxStatistics'. VERBOSE: Importing cmdlet 'Get-EXOMobileDeviceStatistics'. VERBOSE: Importing cmdlet 'Get-EXORecipient'. VERBOSE: Importing cmdlet 'Get-EXORecipientPermission'. VERBOSE: Importing cmdlet 'Get-MyAnalyticsFeatureConfig'. VERBOSE: Importing cmdlet 'Get-OwnerlessGroupPolicy'. VERBOSE: Importing cmdlet 'Get-UserBriefingConfig'. VERBOSE: Importing cmdlet 'Get-VivaInsightsSettings'. VERBOSE: Importing cmdlet 'Set-MyAnalyticsFeatureConfig'. VERBOSE: Importing cmdlet 'Set-OwnerlessGroupPolicy'. VERBOSE: Importing cmdlet 'Set-UserBriefingConfig'. VERBOSE: Importing cmdlet 'Set-VivaInsightsSettings'. VERBOSE: Importing function 'Connect-ExchangeOnline'. VERBOSE: Importing function 'Connect-IPPSSession'. VERBOSE: Importing function 'Disconnect-ExchangeOnline'. PS>TerminatingError(EWSContactSync.ps1): "Cannot convert the "System.Management.Automation.PSCredential" value of type "System.Management.Automation.PSCredential" to type "System.Security.SecureString"." Cannot convert the "System.Management.Automation.PSCredential" value of type "System.Management.Automation.PSCredential" to type "System.Security.SecureString". C:\EWS-Office365-Contact-Sync\EWSContactSync.ps1 : Cannot convert the "System.Management.Automation.PSCredential" value of type "System.Management.Automation.PSCredential" to type "System.Security.SecureString".

Based on the error message, it appears that there is an issue with converting a value from type "System.Management.Automation.PSCredential" to type "System.Security.SecureString." I have reviewed the script and checked the input parameters, but I haven't been able to resolve the problem.

I want to ensure that the scripts called "Create-SecureCertificatePassword.ps1" and "Create-SecureCredential.ps1" are still providing the correct inputs

I would greatly appreciate your guidance and support in resolving this issue. Could you please review the provided error transcript and offer any insights or solutions? If there are any specific steps or troubleshooting methods I should try, please let me know.

Thank you in advance for your time and assistance. I look forward to your response and resolving this issue.

Best regards, Stefan

sbakkerlukkien commented 1 year ago

I would like to inform you that we have found a potential workaround for this issue. By using the newest version of the ExchangeOnlineModule (version 3.1.0), we were able to overcome the conversion problem. It is interesting to note that previous ticket statements recommended using version 2.0.5, but the newer version seems to provide a resolution.

While this workaround has allowed us to proceed with the script, we would still appreciate your guidance and support in understanding the root cause of the conversion error and any potential implications of using the newer version of ExchangeOnlineModule.

grahamr975 commented 1 year ago

@sbakkerlukkien To resolve the error for converting "System.Management.Automation.PSCredential" to type "System.Security.SecureString", you must regenerate your encrypted credential file using the Getting Started\Create-SecureCertificatePassword.ps1 script. This will create an encrypted secure string, which should be the secret key to your Certificate & AzureApp. Please refer to this repo's readme.