[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

GPO Script

Posted on 2010-09-16
10
Medium Priority
?
804 Views
Last Modified: 2012-05-10
I need help creating a GPO script to rename the outlook.nk2 (email cache file) to oldoutlook.nk2. The current script is currently set to just delete the file, however, we now have a need to save the old file first. Is it possible to have it run just once? Sorry, this is new territory for me!

Current script.....

On Error Resume Next


Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")
Set WSHShell = CreateObject("WScript.Shell")


Set colProcess = oWMIService.ExecQuery("Select * from Win32_Process")
For Each oProcess in colProcess
If lCase(oProcess.Name) = "outlook.exe" Then
oProcess.Terminate()
WScript.Sleep 10000
End If
Next


userProfile = WSHShell.ExpandEnvironmentStrings("%userprofile%")
strOutlookfolder = userProfile & "\Application Data\Microsoft\Outlook\"


If oFSO.FolderExists(strOutlookfolder) Then
Set strFolder = oFSO.GetFolder(strOutlookfolder)
For Each strFile in strFolder.Files
If lCase(Right(strFile,4)) = ".nk2" then
oFSO.DeleteFile strFile
End If
Next
Else
End If
0
Comment
Question by:greenasp
[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
  • 7
  • 3
10 Comments
 
LVL 2

Author Comment

by:greenasp
ID: 33694520
curernt script does not work either...lol
0
 
LVL 2

Author Comment

by:greenasp
ID: 33695189
This is the path for the file that needs to be renamed %appdata%\Microsoft\Outlook
0
 
LVL 2

Accepted Solution

by:
Procastin8or earned 2000 total points
ID: 33695633
This worked for me. (I tested it using other files not my .nk2 files)
On Error Resume Next


Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")
Set WSHShell = CreateObject("WScript.Shell")


Set colProcess = oWMIService.ExecQuery("Select * from Win32_Process")
'For Each oProcess in colProcess
'If lCase(oProcess.Name) = "outlook.exe" Then
	'oProcess.Terminate()
	'WScript.Sleep 10000
'End If
'Next


userProfile = WSHShell.ExpandEnvironmentStrings("%userprofile%")
strOutlookfolder = userProfile & "\Application Data\Microsoft\Outlook\"


If oFSO.FolderExists(strOutlookfolder) Then
	Set strFolder = oFSO.GetFolder(strOutlookfolder)
	For Each strFile in strFolder.Files
		If lCase(Right(strFile,4)) = ".nk2" then
			strFileNew = strFile & ".old"
			oFSO.MoveFile strFile , strFileNew
			strFileNew = ""
		End If
	Next
	Else
End If

Open in new window

0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 2

Expert Comment

by:Procastin8or
ID: 33695649
Oops... I forgot, you'll need to uncomment these lines. I didn't want to kill my outlook while testing.
For Each oProcess in colProcess
If lCase(oProcess.Name) = "outlook.exe" Then
	oProcess.Terminate()
	WScript.Sleep 10000
End If
Next

Open in new window

0
 
LVL 2

Expert Comment

by:Procastin8or
ID: 33695665
Also, it was easier to rename to filename.nk2.old than it was to do oldfilename.nk2.
0
 
LVL 2

Author Comment

by:greenasp
ID: 33695686
When I run in powershell I get the following error.  I might be doing something wrong.

On Error Resume Next


Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")
Set WSHShell = CreateObject("WScript.Shell")


Set colProcess = oWMIService.ExecQuery("Select * from Win32_Process")
'For Each oProcess in colProcess
'If lCase(oProcess.Name) = "outlook.exe" Then
      'oProcess.Terminate()
      'WScript.Sleep 10000
'End If
'Next


userProfile = WSHShell.ExpandEnvironmentStrings("%userprofile%")
strOutlookfolder = userProfile & "\Application Data\Microsoft\Outlook\"


If oFSO.FolderExists(strOutlookfolder) Then
      Set strFolder = oFSO.GetFolder(strOutlookfolder)
      For Each strFile in strFolder.Files
            If lCase(Right(strFile,4)) = ".nk2" then
                  strFileNew = strFile & ".old"
                  oFSO.MoveFile strFile , strFileNew
                  strFileNew = ""
            End If
      Next
      Else
End If
Unexpected token 'if' in expression or statement.
At line:11 char:2

Unexpected token 'lCase' in expression or statement.
At line:11 char:5

Unexpected token '(' in expression or statement.
At line:11 char:10

Unexpected token 'oProcess.Name' in expression or statement.
At line:11 char:11

Unexpected token ')' in expression or statement.
At line:11 char:24

Unexpected token 'if' in expression or statement.
At line:11 char:2

Unexpected token 'lCase' in expression or statement.
At line:11 char:5

Unexpected token '(' in expression or statement.
At line:11 char:10

Unexpected token 'oProcess.Name' in expression or statement.
At line:11 char:11

Unexpected token ')' in expression or statement.
At line:11 char:24
0
 
LVL 2

Author Comment

by:greenasp
ID: 33695822
This is what I am currently running in the powershell ise .  Should I be using something else?
On Error Resume Next


Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")
Set WSHShell = CreateObject("WScript.Shell")


Set colProcess = oWMIService.ExecQuery("Select * from Win32_Process")

For Each oProcess in colProcess
If lCase(oProcess.Name) = "outlook.exe" Then
	oProcess.Terminate()
	WScript.Sleep 10000
End If
Next


userProfile = WSHShell.ExpandEnvironmentStrings("%userprofile%")
strOutlookfolder = userProfile & "\Application Data\Microsoft\Outlook\"


If oFSO.FolderExists(strOutlookfolder) Then
	Set strFolder = oFSO.GetFolder(strOutlookfolder)
	For Each strFile in strFolder.Files
		If lCase(Right(strFile,4)) = ".nk2" then
			strFileNew = strFile & ".old"
			oFSO.MoveFile strFile , strFileNew
			strFileNew = ""
		End If
	Next
	Else
End If

Open in new window

0
 
LVL 2

Author Closing Comment

by:greenasp
ID: 33696086
Thank You!
0
 
LVL 2

Author Comment

by:greenasp
ID: 33697074
it looks like it did not change the file name at %appdata%\microsoft\outlook
0
 
LVL 2

Author Comment

by:greenasp
ID: 33698844
Sorry, did work! thanks!
0

Featured Post

Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

649 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