Hello All,
I am working on a script to Upload EML messages to Exchange online, the script works fine if you are going to upload single EML message, but if you tried to loop through the EML messages (10,000) you will get an error
"Exception calling "Save" with "1" argument(s): "This operation can't be performed because this service object already has an ID. To update this service object, use the Update() method instead."
and if you used the Update() method you will get this error
"Cannot convert argument "conflictResolutionMode", with value: "AAMkADQzYzJlYmY4LWQ0MTktNDI1OC1hMzk5LTU1NjY4MzEyZDllYQAuAAAAAAC9KBW4BKndR6JlMKNDzhBDAQB8rggXOc1YSrfw79e+XiMYAAAAxmsZAAA=", for "Update" to type
"Microsoft.Exchange.WebServices.Data.ConflictResolutionMode": "Cannot convert the "AAMkADQzYzJlYmY4LWQ0MTktNDI1OC1hMzk5LTU1NjY4MzEyZDllYQAuAAAAAAC9KBW4BKndR6JlMKNDzhBDAQB8rggXOc1YSrfw79e+XiMYAAAAxmsZAAA=" value of type
"Microsoft.Exchange.WebServices.Data.FolderId" to type "Microsoft.Exchange.WebServices.Data.ConflictResolutionMode".
I tried to make 1 save action and then update but also i failed
could you help please
$UserName = "user@domain.com" $Password = "password" $secpassword = ConvertTo-SecureString $Password -AsPlainText -Force $adminCredential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName,$secpassword If(Get-PSSession | where-object {$_.ConfigurationName -eq "Microsoft.Exchange"}){ write-host "Session Exists" } else{ $rpRemotePowershell = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -credential $adminCredential -Authentication Basic -AllowRedirection $importresults = Import-PSSession $rpRemotePowershell } $dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll" [void][Reflection.Assembly]::LoadFile($dllpath) $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013) $windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent() $sidbind = "LDAP://<SID=" + $windowsIdentity.user.Value.ToString() + ">" $aceuser = [ADSI]$sidbind $service.Credentials = New-Object System.Net.NetworkCredential($username,$password) $service.AutodiscoverUrl("user@tenant.onmicrosoft.com" ,{$true}) $MailboxName="taheito@mydomain.com" $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName) $Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid) $emUploadEmail = new-object Microsoft.Exchange.WebServices.Data.EmailMessage($service) $EMLsFiles = Get-ChildItem -Path "D:\Temp_Files\" -Recurse Foreach ($EMLItem in $EMLsFiles){ [byte[]]$bdBinaryData1 = [System.IO.File]::ReadAllBytes($EMLItem.FullName) $emUploadEmail.MimeContent = new-object Microsoft.Exchange.WebServices.Data.MimeContent("us-ascii", $bdBinaryData1); $PR_Flags = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(3591, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer); $emUploadEmail.SetExtendedProperty($PR_Flags,"1") $emUploadEmail.Save($Inbox.Id) }