Tuesday, March 13, 2012

Outlook Anywhere With Self Signed Certificates

General consensus seems to be that you need a proper certificate from a trusted authority before you can get outlook anywhere working. Don't believe them because you can have OWA with a self signed cert.

It's a matter of matching the CN with the address in the url/outlook account. In Exchange shell you'll need a new certificate if they dont yet match:

New-ExchangeCertificate -PrivateKeyExportable $True -Services “IMAP, POP, IIS, SMTP” -SubjectName “cn=external.domain.name"

Enable the certificate and ensure all services are enabled on it.
Enable-ExchangeCertificate -Thumbprint [THUMBPRINT FROM NEW CERT]

Check certs and they're services:

Get-ExchangeCertificate |FL 


Then  import the certificate from IE into your 'Trusted Root Certificate Store".

Should work then..

The assumption is that you have a static IP for your exchange box, but what if you're using a dynamic one with something like dyndns? You'll need to map your OWA domain to whatever the CN your exchange cert is using. Here's a batch file to map a domain of your choice to any other IP based on it's ping result.

Logic as follows:

1. Ping dyndns domain to get current dynamic IP
2. Write IP to host file and map to domain of choice.
3. Put batch file in startup to have updated always in host file

Note: disable UAC in Vista/7



Paste in .bat and replace 'server.to.ping' and 'host.name.in.certificate.org':

@echo off
setlocal EnableDelayedExpansion
set myServer=server.to.ping

for /f "tokens=1,2 delims=[]" %%a IN ('ping -n 1 !myServer!') DO (
 if "%%b" NEQ "" set ip=%%b
)


echo %ip%>newip.txt



pushd "%systemroot%\system32\drivers\etc"
type hosts|find /i /v "#zzz" > hosts.new
move "%cd%\hosts.new" "%cd%\hosts"
for /f "usebackq" %%a in ("C:\newip.txt") do (
>>hosts echo %%a      host.name.in.certificate.org #zzz.
)
popd





pcname is not setup to establish a connection on port "File and Print Sharing (SMB)" with this computer

If you've run into this charming message trying to get some file sharing up and running - try flipping this registry key:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\LanManWorkstation\Parameters

EnableSecuritySignature 

Change it to 0. This toggles SMB signing. Tested on Vista. Dont forget the other usaul suspects - firewalls, antivirus, ect.

Tuesday, March 30, 2010

PST Script Based Delta Backup (locked PST's)


PST's are a hassle. They're big and tricky to backup since they're always in use. Copying them for backup purposes also takes a long time - even worse when you're trying to backup 2GB+ pst files accross a wireless LAN.


This guy uses a method that employs a Windows port of rdiff. Awesome! I thought I'd adapt this for my purposes and mix it with this command line pst volume shadow copy script and share it. The end result is scripted method to create delta files that includes only changes from an in-use/locked pst.

This script is to backup a pst using the rdiff algorithm (ie, only internal file changes are backed up so you dont have to backup an entire pst everytime!). This delta file is much much smaller than the orignal pst thus it much more manageable. If you need to restore the pst then you merge the original pst with its latest delta file. Using vshadow.exe (volume shadow copy) you can do all this while outlook is open and the pst is in use.

Once off Manual Part:

1. Create a signature file from the original pst using the rdiff port for windows.
2. Backup full pst that the signature is based on in a safe place.

Scripted Part:

All is contained in a .cmd file that calls vshadow.exe, dosdev.exe, rdiff.exe and finally robocopy.exe. Logic is as follows:

1. Run vshadow.exe and create a shadow volume of drive
2. Mount shadow volume on a drive letter using dosdev.exe
(now all locked files are available for you convenience!)
3. Create a delta of the pst (ie, create a separate file containing only the changes since the
last signature.)
4. Use robocopy to copy the delta file to backup area of your choice

So in the folder you need the following:

c:\vshadow\
...............vshadow.exe (the right version for XP/Vista - see here for more info)
...............dosdev.exe
...............rdiff.exe
...............cygwin.dll
...............dummy.txt
............................\delta
............................\signature


Copy and paste into vss.cmd (some of it is hardcoded to a directory 'vshadow' in c:\) :
(Script modified from here - thanks)

setlocal

@REM test if we are called by VSHADOW
if NOT "%CALLBACK_SCRIPT%"=="" goto :IS_CALLBACK

@REM
@REM Get the source and destination path
@REM

set SOURCE_DRIVE_LETTER=%~d1
set SOURCE_RELATIVE_PATH=%~pnx1
set DESTINATION_PATH=%2
@REM
@REM Create the shadow copy - and generate env variables into a temporary script.
@REM
@REM Then, while the shadow is still live
@REM recursively execute the same script.
@REM
@echo ...Determine the scripts to be executed/generated...
set CALLBACK_SCRIPT=%~dpnx0
set TEMP_GENERATED_SCRIPT=GeneratedVarsTempScript.cmd
@echo ...Creating the shadow copy...
%~dp0\vshadow.exe -script=%TEMP_GENERATED_SCRIPT% -exec=%CALLBACK_SCRIPT% %SOURCE_DRIVE_LETTER%
del /f %TEMP_GENERATED_SCRIPT%
@goto :EOF
:IS_CALLBACK
setlocal
@REM
@REM This generated script should set the SHADOW_DEVICE_1 env variable
@REM
@echo ...Obtaining the shadow copy device name...
call %TEMP_GENERATED_SCRIPT%
REM Mount shadow Volume on S:
dosdev S: %SHADOW_DEVICE_1%
REM Create Delta file of OST/PST usinf S: shadow volume
REM Substite to your PST path
rdiff delta signature\sig.rdf "S:\Documents and Settings\User\Local Settings\Application Data\Microsoft\Outlook\outlook.ost" delta\delta.rdf
REM Copy Delta to Backup Location
robocopy delta c:\Backup-Location

REM Unmount S: drive
dosdev -r -d S:


Note:

vss.cmd needs arguments. Run with "vss.cmd c:\dummy.txt" this tells the shadow copy which drive you want a shadow copy of. (This is a hack I know. The script is originally made to copy locked files and those are specified in the arguments. Read up on the orignal script here).

Restore a PST

Use the the original pst and merge with the last delta file using rdiff.

The great thing about this is that the script takes very little time to complete. You can also make itcompletely invisible to the end user by calling the command file with a simple VB script:

Copy and paste into a .vbs file:

Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN("vss.cmd c:\vshadow\dummy.txt c:\vshadow\dummy.txt", 0, True)
Set WshShell = Nothing

This is just one use of creating shadow copies from a commandline. Once you have the shadow copy mounted using the dosdev function you can do all sorts off stuff with the locked files.

Also slapping a GUI over these scripts wouldn't be too hard...   

Note:
This has not been tested extensively so use at own risk!