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
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
12 Comments
 
LVL 70

Expert Comment

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

Author Comment

by:donander
ID: 40380886
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 70

Expert Comment

by:Qlemo
ID: 40380972
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 70

Expert Comment

by:Qlemo
ID: 40381058
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 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40381198
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
 

Author Comment

by:donander
ID: 40416174
Sorry about the delay in responding. I will test this early next week.
Thanks,
Don
0
 
LVL 40

Expert Comment

by:footech
ID: 40450822
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 70

Expert Comment

by:Qlemo
ID: 40451227
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 40

Expert Comment

by:footech
ID: 40453248
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 70

Expert Comment

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

Author Closing Comment

by:donander
ID: 40505240
Thanks!
Don
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

728 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