Copying NK2 files from TS Profiles to new TS .V2 Profile.

ihotdesk
ihotdesk used Ask the Experts™
on
Hi there,

I am wanting to create a script to copy users NK2 file from their old profile to their new one when logged into the new TS server. The old TS server was a 2003 Server (hence old profiles...documents and settings)

The new TS server is a 2008 server, therefore new V2 profile. I have tried using this script:


Dim WshShell : Set WshShell = Wscript.CreateObject("Wscript.Shell")
Dim fso : Set fso = Wscript.CreateObject("Scripting.FileSystemObject")
Dim oNet : Set oNet = Wscript.CreateObject("Wscript.Network")
Dim WshEnv : Set WshEnv = WshShell.Environment("Process")
SysDrive = WshEnv("%SystemDrive%")

sFolder = "\\serverdc01\tsprofiles$" & oNet.Username & "\Application Data\Microsoft\Outlook" 'folder to look in
dFolder = SysDrive & "\users\" & oNet.Username & "\appdata\roaming\microsoft\outlook"
IF fso.FolderExists(sFolder) Then


Set oFolder = fso.GetFolder(sFolder)
Set oFiles = oFolder.Files
FOR Each oFile In oFiles
ext = fso.GetExtensionName(oFile)
' check if characters in file extension is "NK2"
IF UCase(ext) = "NK2" Then
Wscript.Echo "NK2 file exists" 'Backup the file NK2 to a server.
Wscript.Echo ext

Set oFolder = fso.CreateFolder(dfolder)
fso.copyfile ofile.path, dfolder
End If
Next
End If


But it doesnt seem to work. I'm not very good at vbscripts so thats probably why! Can anyone advise on this or advise an easy way to do this. They really need the nk2 copied from their old profile location to their new profile. One thing I did notice was that on the old server the profile folders are all username.domainname

e.g.   jsoap.example   (domain being: example)

Anyone have any helpful tips for me to try? Thanks in advance!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
SteveArchitect/Designer

Commented:
Does it copy a file across or fail?

Whats this bit for?

t oFolder = fso.GetFolder(sFolder)
Set oFiles = oFolder.Files
FOR Each oFile In oFiles
ext = fso.GetExtensionName(oFile)
' check if characters in file extension is "NK2"
IF UCase(ext) = "NK2" Then
Wscript.Echo "NK2 file exists" 'Backup the file NK2 to a server.
Wscript.Echo ext

Cant you just  go straight ahead and copy the file, as its always called outlook.nk2 anyway?
Also have you checked the users have access to the \\serverdc01\tsprofiles$ share from the new server?
Hi

I recreated and fixed the script for you. I added the following:

The script check if the target path exists if it doesn't it recreates all missing folders (not just the last one as before)

The script will not copy the file if the file already exists on the target folder. (This can be removed if you wish)

As the folder path contains username.domain, I added a new variable to take the domain name; just insert your domain as it appears on the source domain on the variable strDomain

Always leave the “On Error Resume Next” when releasing the script to users so they don't receive an error message. Remove is for testing purposes

Make sure the paths are correct.

You can use Wscript.Echo strSourceFolder or strTargetFolder to view the full path in a pop up box

Cheers

On Error Resume Next

strDomain = "DOMAIN_NAME"

Const OverwriteExisting = True
Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oNet = Wscript.CreateObject("Wscript.Network")

SysDrive = WshShell.ExpandEnvironmentStrings("%SystemDrive%")
strSourceFolder = "\\serverdc01\tsprobjFiles$" & oNet.Username & "." & strDomain & "\Application Data\Microsoft\Outlook\" 
strTargetFolder = SysDrive & "\users\" & oNet.Username & "\appdata\roaming\microsoft\outlook\"


'Checks if the target folder exists if not it creates it
If objFSO.FolderExists(strTargetFolder) Then
Else
	Create_Folder(strTargetFolder)
End If

If objFSO.FolderExists(strSourceFolder) Then
	Set objFolder = objFSO.GetFolder(strSourceFolder)
	Set objFiles = objFolder.Files
	For Each objFile In objFiles
		ext = objFSO.GetExtensionName(objFile)
		IF UCase(ext) = "NK2" Then	
	
			If objFSO.FileExists(strTargetFolder & objFile.name) Then
			Else
				objFSO.CopyFile objFile.path , strTargetFolder, OverwriteExisting
			End If
			
		End If
	Next
End If


Function Create_Folder(strTargetFolder)

	arrTargetFolderPath = Split(strTargetFolder,"\")
	strFolder = arrTargetFolderPath(0)
	For i=1 To UBound(arrTargetFolderPath)
		strFolder = strFolder & "\" & arrTargetFolderPath(i)
		If objFSO.FolderExists(strFolder) Then
		Else
			Set objFolder = objFSO.CreateFolder(strFolder)
		End If
	Next
	
End Function

Open in new window

wow, thanks for this. just what i needed as well.

Now lets see if i can modify it to copy the IE favourites folder from old to new...

Jono.
were you able to figure out how to copy favorites?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial