Solved

I need a PS script to remotely copy local PST files to network and remotely reconfigure Outlook to use the PST on the network

Posted on 2014-10-14
12
166 Views
Last Modified: 2014-12-17
In our environment we want to store users' Outlook PST files on the network because we do not backup the local workstations. We know there are some workstations where Outlook is using local PSTs. I got a Powershell script to find local Outlook PST files in EE question Q_28533359. This found many workstations with local PSTs. Now I am hoping it is possible to use a Powershell script to remotely copy these to the network home directory for the user and to configure Outlook to use the PST file on the network instead of on the local workstation. I realize this may require running the script locally with the user whose PST we want to move logged on but if it is possible to do remotely without the user logged on that would be preferable. If this is only possible with VB script I would accept that but would prefer Powershell.
0
Comment
Question by:donander
  • 6
  • 3
  • 2
12 Comments
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
You are aware that you should never use a PST stored on network?
0
 

Author Comment

by:donander
Comment Utility
Yes I am aware that is what Microsoft says but we do not backup our workstations so this is our only recourse. We have been storing and using PSTs on network drives since I came to work at this company in 1998 and have never had any problems related to storing them on the network.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
Then you were very lucky. Many folks will tell you that regular PST repairs are required ...

IMHO the best approach is to use a login script to perform the change. Otherwise you would have to load the user profile, or mount the user hive, to perform changes.

Edit: Above assumes you insist on having network share PSTs. The common way to handle the backup issue is to perform a backup prior to starting Outlook, and keeping PSTs local.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
The VBS in http://community.spiceworks.com/scripts/show/2320-update-pst-path-registry looks promising, and I'm hesitant to convert that to PS, as I'm not fully clear about how it works.
The script mails to Help Desk, but if you replace that by a copy command you should be fine (use FileSystemObject for performing the copy / move).
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
Comment Utility
Here is the converted and simplified PS counterpart, currently in test mode (= changing nothing - see comments for what to change for getting the real experience). Still it processes the current, local user profile only.
cls
# *** change this to your destination root
$UNCLocation = "\\server\pstshare\$env:UserName\"
dir -Recurse 'HKCU:Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook' |
  ? { $_.Property -contains "001f6700" } |
  % {
    get-itemproperty $_.PsPath "001f6700"
  } |
  % {
    $bytes = $_."001f6700"
    $curpath = (-join [Char[]] $(foreach ($i in 1..($bytes.Count-1)) { if ($i % 2) { $bytes[$i]*256 + $bytes[$i-1] } })).Trim(0)
    if ($curpath -like "?:*") {
      Write-Host "Local path found in $($_.PsPath.Replace($_.PsProvider.ToString()+'::','')): $curpath"
      Move-Item $curpath $UNCLocation -whatif   # *** Remove -whatif if certain
      if ($?) {
        $newpath = Join-Path $UNCLocation (split-path -Leaf $curpath)
        # *** replace "001f6700 test" with "001f6700" if certain
        Set-ItemProperty $_.PsPath "001f6700 test" -value ([Byte[]]($(foreach ($i in ([byte[]] [Char[]] $newpath)) { $i, 0 })+@(0,0)))
      }
    }
  }

Open in new window

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:donander
Comment Utility
Sorry about the delay in responding. I will test this early next week.
Thanks,
Don
0
 
LVL 39

Expert Comment

by:footech
Comment Utility
Just thought I would contribute something as recently I've been looking at the ways (where I could find them) that strings are stored as byte arrays, hex representations, etc. in registry values and other places.

You could replace line 11 with
$curpath = [text.encoding]::Unicode.GetString($bytes)

Open in new window

and also line 18 with
Set-ItemProperty $_.PsPath "001f6700 test" -value ([text.encoding]::Unicode.GetBytes($newpath))

Open in new window

I noticed in line 18 of Qlemo's code that it adds a couple of zeros at the end of the byte array.  When comparing to an existing registry entry, these appear to be extra and unneeded.  The [text.encoding]::Unicode.GetBytes($newpath) bit doesn't create those extra zeros.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
footech,
Using Text.Encoding class is a good idea (and thanks for bringing that in). However, those registry values for paths are ending with an U0000 (hex 00 00), which needs to get removed when using as pathname, and added back for registry values. The appended zeroes are not unneeded.
So line 11 needs to be
$curpath = [text.encoding]::Unicode.GetString($bytes).Trim(0)

Open in new window

and line 18
Set-ItemProperty $_.PsPath "001f6700 test" -value ([text.encoding]::Unicode.GetBytes($newpath+[char]0))

Open in new window

0
 
LVL 39

Expert Comment

by:footech
Comment Utility
You are correct.
I took a second look at why I didn't think they were necessary and saw that I had re-used a variable I shouldn't have, so when I tested it looked like there was an extra set of "00 00" at the end.  My mistake and thanks for the correction.
Don't you just love dealing with invisible characters in strings?
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
Oh yes, they are great. Garbled output, strange concatenation, length mismatches, …
0
 

Author Closing Comment

by:donander
Comment Utility
Thanks!
Don
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
A procedure for exporting installed hotfix details of remote computers using powershell
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now