new-mailboxexportrequest not working properly

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 11 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
rtiel1
Posts: 15
Last visit: Tue Nov 19, 2019 12:05 am

new-mailboxexportrequest not working properly

Post by rtiel1 »

I'm running the below script in Powershell Studio 2012 which is not running properly. I want to export a mailbox to a pst file which works great when I run the script directly in the Exchange Management Shell. But when executing the script from Powershell Studio 2012 the export request is generated but the status stays on "queued". No pst file is created till I execute a command to remove the export request, then the pst file is created???Can anyone help me? Because it runs in EMS I think it's a Powershell Studio 2012 issue...Thnx Remco# Exchange 2010 SP1 Mailbox Export Script # Steve Goodman. Use at your own risk! #http://www.stevieg.org/tag/new-mailboxexportrequest/ ############### # Settings # ############### # Pick ONE of the two below. If you choose both, it will use $Server. $Server = "Exchange" $Database = "" # Share to export mailboxes to. Needs R/W by Exchange Trusted Subsystem # Must be a UNC path as this is run by the CAS MRS service. $ExportShare = "[LOCATION]" # After each run a report of the exports can be dropped into the directory specified below. (The user that runs this script needs access to this share) # Must be a UNC path or the full path of a local directory. $ReportShare = "[LOCATION]" # Shall we remove the PST file, if it exists beforehand? (The user that runs this script needs access to the $ExportShare share) # Valid values: $true or $false $RemovePSTBeforeExport = $false ############### # Code # ############### if ($Server) { if (!(Get-ExchangeServer $Server -ErrorAction SilentlyContinue)) { throw "Exchange Server $Server not found"; } if (!(Get-MailboxDatabase -Server $Server -ErrorAction SilentlyContinue)) { throw "Exchange Server $Server does not have mailbox databases"; }$Mailbox = get-mailbox "FTest" # Pre-checks done # Queue all mailbox export requestsif ($RemovePSTBeforeExport -eq $true -and (Get-Item "$ExportShare$($Mailbox.Alias).pst" -ErrorAction SilentlyContinue)) { Remove-Item "$ExportShare$($Mailbox.Alias).pst" -Confirm:$false } New-MailboxExportRequest -Mailbox $Mailbox.Alias -FilePath "$ExportShare$($Mailbox.Alias).pst" Write-Output "Waiting for export to complete" # Wait for mailbox export requests to complete while ((Get-MailboxExportRequest | Where {$_.Status -eq "Queued" -or $_.Status -eq "InProgress"})) { sleep 10 } # Write reports if required if ($ReportShare) { Write-Output "Writing reports to $ReportShare" $Completed = Get-MailboxExportRequest | Where {$_.Status -eq "Completed"} | Get-MailboxExportRequestStatistics | Format-List if ($Completed) { $Completed | Out-File -FilePath "$ReportShare$($Mailbox.Alias)_Completed.txt" } $Incomplete = Get-MailboxExportRequest | Where {$_.Status -ne "Completed"} | Get-MailboxExportRequestStatistics | Format-List if ($Incomplete) { $Incomplete | Out-File -FilePath "$ReportShare$($Mailbox.Alias)_Incomplete.txt" } } # Remove Requests Get-MailboxExportRequest | Remove-MailboxExportRequest -Confirm:$false}
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

new-mailboxexportrequest not working properly

Post by davidc »

Please include the following:PowerShell Studio versionPowerShell VersionThe selected Platform (32bit or 64bit / Elevated) in PowerShell Studio when running the script Does PowerShell Studio have the same permissions as the Exchange Management Shell? David
David
SAPIEN Technologies, Inc.
User avatar
rtiel1
Posts: 15
Last visit: Tue Nov 19, 2019 12:05 am

new-mailboxexportrequest not working properly

Post by rtiel1 »

Hello David, Thnx for your reply. I'm using the latest fully updated Powershell Studio 2012 version and tried the script in 32bit and 64bit (not elevated though), powershell is version 2. After some more testing I found out that the script does work if I open Powershell Studio 2012 for the first time and run the project for the first time . I use this script in a form and when I execute the script a second time for a different user, that's when it goes wrong. Does this mean it's some kind of powershell session issue? Remco
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

new-mailboxexportrequest not working properly

Post by davidc »



Could
be, but I
David
SAPIEN Technologies, Inc.
User avatar
rtiel1
Posts: 15
Last visit: Tue Nov 19, 2019 12:05 am

new-mailboxexportrequest not working properly

Post by rtiel1 »

ok, thnx
User avatar
rtiel1
Posts: 15
Last visit: Tue Nov 19, 2019 12:05 am

new-mailboxexportrequest not working properly

Post by rtiel1 »

I've done some more testing. I executed the same script within PowerGUI and that's working as it should, every time I run it.That's why I think it has something to do with Powerstudio 2012...... However in both apllications I recieve an exception but that's I believe an Exchange issue.: EXCEPTION: The cmdlet extension agent with the index 0 has thrown an exception in OnComplete(). The exception is: System.InvalidOperationException: Operation is not valid due to the current state of the object.
bij Microsoft.Exchange.Data.Storage.ExchangePrincipal.get_ServerFullyQualifiedDomainName()
bij Microsoft.Exchange.Data.Storage.MailboxSession.Initialize(MapiStore linkedStore, LogonType logonType, ExchangePrincipal owner, DelegateLogonUser delegateUser, Object identity, OpenMailboxSessionFlags flags, GenericIdentity auxiliaryIdentity)
bij Microsoft.Exchange.Data.Storage.MailboxSession.<>c__DisplayClass12.<CreateMailboxSession>b__10(MailboxSession mailboxSession)
bij Microsoft.Exchange.Data.Storage.MailboxSession.InternalCreateMailboxSession(LogonType logonType, ExchangePrincipal owner, CultureInfo cultureInfo, String clientInfoString, IAccountingObject budget, Action`1 initializeMailboxSession, InitializeMailboxSessionFailure initializeMailboxSessionFailure)
bij Microsoft.Exchange.Data.Storage.MailboxSession.CreateMailboxSession(LogonType logonType, ExchangePrincipal owner, DelegateLogonUser delegateUser, Object identity, OpenMailboxSessionFlags flags, CultureInfo cultureInfo, String clientInfoString, PropertyDefinition[] mailboxProperties, IList`1 foldersToInit, GenericIdentity auxiliaryIdentity, IAccountingObject budget)
bij Microsoft.Exchange.Data.Storage.MailboxSession.ConfigurableOpen(ExchangePrincipal mailbox, MailboxAccessInfo accessInfo, CultureInfo cultureInfo, String clientInfoString, LogonType logonType, PropertyDefinition[] mailboxProperties, InitializationFlags initFlags, IList`1 foldersToInit, IAccountingObject budget)
bij Microsoft.Exchange.Data.Storage.MailboxSession.OpenAsSystemService(ExchangePrincipal mailboxOwner, CultureInfo cultureInfo, String clientInfoString)
bij Microsoft.Exchange.ProvisioningAgent.MailboxLoggerFactory.XsoMailer.Log(AdminLogMessageData data, LogMessageDelegate logMessage)
bij Microsoft.Exchange.ProvisioningAgent.AdminLogProvisioningHandler.OnComplete(Boolean succeeded, Exception e)
bij Microsoft.Exchange.Provisioning.ProvisioningLayer.OnComplete(Task task, Boolean succeeded, Exception exception)
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

new-mailboxexportrequest not working properly

Post by davidc »

Every time you run a script PowerShell Studio creates a new runspace/instance of PowerShell. It is possible this script could have a flaw where something is not closing correctly and possibly causing it to lock. The exception is obvious indication that something isn't right. I believe the Exchange Management Shell has preloaded scripts / objects that are required. Please refer to the following technet post and let me know if it helps:http://social.technet.microsoft.com/For ... a0831e3564 Blog post mentioned in the forum post:http://www.mikepfeiffer.net/2010/02/man ... owershell/ David
David
SAPIEN Technologies, Inc.
This topic is 11 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.