header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Move users PST file then reconnect
Last Post 19 Mar 2011 07:49 PM by goldendel. 11 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
KhabelUser is Offline
New Member
New Member
Posts:6
Avatar

--
10 Mar 2010 12:30 PM
    I'm in the process of moving all PSTs to a central repository but need a way to reconnect them to a users outlook once moved, any help would be greatly appreciated
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    11 Mar 2010 04:02 AM
    Here's how to attach a pst to outlook, just change the path to the pst file.

    $ol = new-object -com outlook.application
    $ns = $ol.getNamespace("MAPI")
    $ns.AddStore("D:\outlook.pst")

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    KhabelUser is Offline
    New Member
    New Member
    Posts:6
    Avatar

    --
    11 Mar 2010 12:48 PM
    Thanks


    KhabelUser is Offline
    New Member
    New Member
    Posts:6
    Avatar

    --
    14 Mar 2010 02:29 PM
    Is there anyway to do this without having to install powershell on each users machine?
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    15 Mar 2010 01:02 AM
    You can try the same code in vbscript.

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    15 Mar 2010 01:05 AM
    You can try the same code in vbscript.

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    KhabelUser is Offline
    New Member
    New Member
    Posts:6
    Avatar

    --
    08 Apr 2010 07:06 PM
    Have got the PSTs moved and reconnected via powershell perfectly thanks to your help however the only problem I have now is when the user opens outlook they still have a personal folder pointing to the old PST location as well as one pointing to the new location, is there anyway to remove the old personal folder?
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    09 Apr 2010 03:01 AM
    IIRC $ns has a RemoveStore() method.

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    goldendelUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    05 Mar 2011 05:25 AM
    Hi,

    There is a removestore method.  I'm having problems using it I'm using the following code:

    $OL = new-object -com outlook.application
    $NS = $OL.getNamespace("MAPI")
    $PSTPath = "C:\Temp\Backup.Pst"
    $NS.addStore($pstpath)
    $PSTFolder = $NS.stores | Where {$_.FilePath -eq $PSTPath} | ?{$NS.GetFolderFromID($_.StoreID)} $NS.RemoveStore($PSTFolder)

    I get this error:

    Cannot convert argument "0", with value: "System.__ComObject", for "RemoveStore " to type "Microsoft.Office.Interop.Outlook.MAPIFolder": "Cannot convert the "S ystem.__ComObject" value of type "System.__ComObject#{000630c7-0000-0000-c000-0 00000000046}" to type "Microsoft.Office.Interop.Outlook.MAPIFolder"." At C:\Users\goldendel\Desktop\test.ps1:6 char:16 + $NS.RemoveStore <<<< ($PSTFolder) + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

    Any clues on how I can get this working please?

    Many thanks,

    goldendel
    goldendelUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    19 Mar 2011 05:03 AM
    I finally got this working with some help.  For anyone else looking, the RemoveStore method does not work properly via the normal powershell 2.0 methods. However, it can be done with Reflection. Here is the sample code to create a PST, backup selected folders and then disconnect the PST. The most difficult bit by far was the disconnect. It is working with Outlook 2010:
     
    $outlook = New-Object -ComObject Outlook.Application $namespace = $outlook.getnamespace("MAPI")
    $Calendar = $namespace.GetDefaultFolder(9)
    $Contacts = $namespace.GetDefaultFolder(10)
    $Tasks = $namespace.GetDefaultFolder(13)
    $Notes = $namespace.GetDefaultFolder(12)
    $Drafts = $namespace.GetDefaultFolder(16)
    $PSTPath = "C:\Temp\Example.Pst"
    $PSTDisplayName = "Backup" #Define variable for DisplayName

    $namespace.AddStore($PSTPath) #Attach .PST
    $PST = $namespace.Stores | ? {$_.FilePath -eq $PSTPath} #Find Store just attached as .PST
    $PSTRoot = $PST.GetRootFolder() #Get Root Folder name of PST
    $PSTRoot.Name = $PSTDisplayName # Change Displayname for PST to Backup

    $Calendar.CopyTo($PST) | out-null #Copy Calendar items to PST
    $Contacts.CopyTo($PST) | out-null #Copy Contact items to PST
    $Tasks.CopyTo($PST) | out-null #Copy Task items to PST
    $Notes.CopyTo($PST) | out-null #Copy Note items to PST
    $Drafts.CopyTo($PST) | out-null #Copy Draft items to PST

    #Cleanup Variables before PST disconnect

    rm variable:Calendar
    rm variable:Contacts
    rm variable:Tasks
    rm variable:Notes
    rm variable:Drafts
    $PSTFolder = $Namespace.Folders.Item($PSTDisplayName) #Bind to PST for disconnection
    $Namespace.GetType().InvokeMember('RemoveStore',[System.Reflection.BindingFlags]::InvokeMethod,$null,$Namespace,($PSTFolder)) #Disconnect .PST

    #Cleanup reamining variables before closure

    rm variable:PSTFolder
    rm variable:PSTDisplayName
    rm variable:PSTRoot
    rm variable:PST
    rm variable:PSTPath
    rm variable:namespace
    rm variable:outlook
    Chris MerrittUser is Offline
    New Member
    New Member
    Posts:28
    Avatar

    --
    19 Mar 2011 10:17 AM
    Shouldn't that be:

    $Calendar.CopyTo($PST) | out-null #Copy Calendar items to PST

    Instead of:

    Calendar.CopyTo($PST) | out-null #Copy Calendar items to PST

    ?
    goldendelUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    19 Mar 2011 07:49 PM
    Thanks Chris. I used the Code button, which then removed all the carraige returns when I edited it to bold the disconnect line.

    I've updated $Calendar and $PSTRoot.Name

    Tim
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer