08-12-2014 02:38 AM
Hi, I have Backup Exec 2012 in my company. Among many jobs there is one for backing up Exchange Server 2010 IIS logs. Since I want to delete these log files after they are backed up (kind of archiving) I can write simply PowerShell script to delete all these files except the newest one (which is locked since it is used by Exchange). It would be nice if there is possibility to run this script automatically immediately after backup job is finished. Is this doable in Backup Exec 2012?
I know there are pre/post commands - does this mean that as a command I can use: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Noninteractive -File "C:\Delete-IISLogFiles.ps1"?
Solved! Go to Solution.
08-20-2014 03:01 AM
08-12-2014 02:53 AM
You could either provide the path to a .bat file containing the script or use the following (as an example) directly:-
c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe test.ps1
08-12-2014 03:03 AM
Yes, I thought like you, I edited my post minutes after you had replied. I will test this next week when IIS logs start to eat my c partition free space on Exchange. PS script is like this (just one line):
Get-ChildItem '\\exchangeservername\c$\inetpub\logs\LogFiles\W3SVC1' | Sort-Object CreationTime -Descending | Select-Object -Skip 1 | Remove-Item -Force
08-12-2014 03:15 AM
Yes, I thought like you. I posted it after you had replied to me. So just to call my ps script:
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Noninteractive -File "C:\Delete-IISLogFiles.ps1"
Which does this:
Get-ChildItem '\\exchangeservername\c$\inetpub\logs\LogFiles\W3SVC1' | Sort-Object CreationTime -Descending | Select-Object -Skip 1 | Remove-Item -Force
08-20-2014 02:26 AM
I tested this but PS script was not executed - all log files are still on Exchange Server. In the attachment I put the screenshoot of job settings related to post-command.
08-20-2014 02:33 AM
Are you able to execute this PS script outside of BE using the BE account ?
Is there any mention of the post command being run/attempted in the job log ?
Is BE 2012 & the remote agents updated with at least SP4 ?
08-20-2014 03:01 AM
In the job log there is a following info:
Starting Post Job Command < c:\Windows\system32\WindowsPowerShell\1.0\powershell.exe -Noninteractive -File "c:\PSScripts\Delete-IISLogFiles.ps1" >
Below that there is a info Completed status: Successful for the job. Now I will restore these files to Exchange Server and run this script from the cmd prompt on BE with BE account (I deleted those files by running ps script from domain controller).
Newest info: I run c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "c:\PSScripts\Delete-IISLogFiles.ps1" from within command prompt on BE server with BE account and it completed successfully - log files on exchange server were deleted.
08-20-2014 03:01 AM
08-20-2014 03:03 AM
It is located in c:\PSScripts folder on the BE server itself.
08-20-2014 03:04 AM
In that case, you should be specifying the post command to run on the BE server itself and not on the remote server.
08-20-2014 03:05 AM
08-20-2014 03:11 AM
Scenario is very simple. PS script file is physically on BE server. It connects to inetpub folder on Exchange Server, lists all log files there and deletes all of them except the newest one. From command prompt on BE server it works fine. Syntax for calling it from BE seems to be a cause of this - otherwise calling ps script from command prompt would also fail.
08-20-2014 03:32 AM
According to all mentioned post command will always run directly on remote server who I am backing up - it tries to find script on remote server c:\PSScripts location which does not exist. This is conclusion?
I tested, it worked. Thanks to all of you.
CONCLUSION: PRE OR POST COMMANDS IN BACKUP JOB ALWAYS RUN DIRECTLY ON REMOTE SERVER THAT IS BEING BACKED UP. SO ANY POWERSHELL SCRIPT CALLED HERE HAS TO BE LOCATED PHYSICALLY ON REMOTE SERVER. THIS WORKS SIMILARLY TO POWERSHELL REMOTE SESSIONS - COMMANDS ENTERED ARE EXECUTING DIRECTLY ON REMOTE COMPUTER.