Share via


powershell outlook

Question

Friday, March 18, 2016 7:51 AM

Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null $oLFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type] $outlook = New-Object -Com Outlook.Application $namespace = $outlook.GetNameSpace("MAPI") $Calendar = $namespace.GetDefaultFolder(9) $PSTPath = "C:\Temp\Example.pst" $PSTDisplayName = "Backup" $namespace.AddStore($PSTPath) $pstFolder = $namespace.Session.Folders.GetLast() $pstFolder.Name = $PSTDisplayName $pstFolder.Folders | ? {$_.Name -ne "Удаленные"} | Foreach {$_.Delete()} $Calendar.CopyTo($pstFolder) $namespace.RemoveStore($pstFolder)

Sorry for my English.
Did he script copies the default calendar set up my file, but if the default calendar delete an event and then re-run the script, remove the event is also deleted in both calendars. I need to make so that after the events of purification of the default calendar by repeated in other calendar events deleted remain in the generated script calendar. help me please

All replies (4)

Friday, March 18, 2016 2:42 PM ✅Answered

The following works as expected for me:  I removed the unneeded lines.

$outlook=New-Object -Com  Outlook.Application
$namespace =$outlook.GetNameSpace('MAPI')
$Calendar = $namespace.GetDefaultFolder(9)

$PSTPath ='C:\Temp\Example.pst'
$PSTDisplayName ="Backup"
$namespace.AddStore($PSTPath)
$pstFolder =$namespace.Session.Folders.GetLast()
$pstFolder.Name = $PSTDisplayName

$pstFolder.Folders|?{$_.Name -ne 'Удаленные'}|%{$_.Delete()}

$Calendar.CopyTo($pstFolder)
$namespace.RemoveStore($pstFolder)
$outlook.Quit()

\(ツ)_/


Friday, March 18, 2016 8:59 AM

Of course, your English is apologized by everyone. But your code is such a way terribly formatted, that you can't really expect that we will have a look on it. And besides, if your code really looks like this in your ISE, debugging is absolutely impossible for you.

This

Add-type
-assembly
"Microsoft.Office.Interop.Outlook"
|
out-null

is one single line:

Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null

Friday, March 18, 2016 2:25 PM

This question would best be serviced by posting in the Outlook Developer forum.

\(ツ)_/


Monday, March 21, 2016 9:50 AM

Hi Bandy,

Thank you for choosing Techent Powershell Forum, however the code format you post is really hard to understand, this would cost us more time to try to re-format your code and then to do the troubleshooting.

I would suggest you post your code just as Jrv and hpotsirhc did as above.

You could test the code from jrv and check if it works for you.

Any issue, feel free to post back.

Best Regards,

Elaine

Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected].