Author |
Message |
kishorepi
Joined: 11 Mar 2013 Posts: 10 Country: United States |
|
Cannot execute powershell script |
|
I have power shell script which deletes files in a folder and sub-folders. This works if i run directly.
Its not doing anything when i run it from 24x7. I might be missing some step or some sort.
Can someone brief out the stepby step instructions that needs to be done to execute powershell script in 24x7 scheduler?
Thank you.
|
|
Mon Mar 11, 2013 4:53 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
Try running 24x7 in Run as Administrator mode
|
|
Mon Mar 11, 2013 6:02 pm |
|
 |
kishorepi
Joined: 11 Mar 2013 Posts: 10 Country: United States |
|
|
|
When i run 24x7 "RunAs Administrator", i got the following error:
JAVA_HOME value must be set to JDK or JRE 1.6.x installation director
Press any key to continue . . .
|
|
Mon Mar 11, 2013 7:31 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
Open command prompt in Run as Admin mode, then
C:
cd C:\24x7
master.bat
|
|
Mon Mar 11, 2013 8:05 pm |
|
 |
kishorepi
Joined: 11 Mar 2013 Posts: 10 Country: United States |
|
|
|
I am running the following:
C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe get-childitem "E:\Program Files\t\t1" -recurse | where {$_.lastwritetime -lt (get-date).adddays(-7) -and -not $_.psiscontainer} |% {remove-item $_.fullname -force}
Log says, job started and finished successfully. But it doesn't delete the files from the folder and sub-folders.
Am i missing anything?
|
|
Wed Mar 13, 2013 7:13 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
Are you starting this command in the right "startup" directory? Does it work if you wrap the command into a batch file and run the batch file instead?
finally, there is another way to do the same thing, deleting files based on their age. check out
http://www.softtreetech.com/24x7/archive/46.htm
 |
 |
FileDir /C "cmd" /P "/c del E:\Program Files\t\t1\" /A 7 /N /S /Q E:\Program Files\t\t1\*.* |
|
|
Wed Mar 13, 2013 10:16 pm |
|
 |
kishorepi
Joined: 11 Mar 2013 Posts: 10 Country: United States |
|
|
|
I tried "FileDir", log says Job started and finished but it doesn't delete the files.
Looks like i am missing some basic thing.
Can you please provide the steps/instructions by each screen?
|
|
Thu Mar 14, 2013 9:54 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
the previous sample for FileDir was incorrect, please try this one
 |
 |
FileDir /C "cmd" /P "/c del " /A 7 /N /S /Q "E:\Program Files\t\t1\*.*" |
If it doesn't work, review captured job output for error messages and other details.
|
|
Thu Mar 14, 2013 10:43 pm |
|
 |
kishorepi
Joined: 11 Mar 2013 Posts: 10 Country: United States |
|
|
|
That didn't work either.
I really want to make it work with PowerShell script as we have lot other things we are planning for which we already have powershell scripts.
Can you please help me how to make it work with powershell script? I tried creating a batch file whch calls the power shell script that isn't working either.
|
|
Fri Mar 15, 2013 4:19 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
Please post the job output so we can see what's not working there
Last edited by SysOp on Sun Mar 17, 2013 9:37 pm; edited 1 time in total |
|
Fri Mar 15, 2013 5:56 pm |
|
 |
kishorepi
Joined: 11 Mar 2013 Posts: 10 Country: United States |
|
|
|
This is all the code in powershell script file (DataDel.ps1, saved at E:\Program Files\t)
--------
get-childitem "E:\Program Files\t\t1" -recurse | where {$_.lastwritetime -lt (get-date).adddays(-7) -and -not $_.psiscontainer} |% {remove-item $_.fullname -force}
--------
This is all the code in batch file ((DataDel.bat, E:\Program Files\t)
--------
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe "& 'E:\Program Files\t\DataDel.ps1'"
--------
Here are the steps i am following while creating the job:
1) Under "Jobs" section, i have created a folder "DataDeletion"
2) Under "DataDeletion", right click and select "New -> Job"
3) At step 1 of job properties wizard, named new job as "DataDel_BatchCallPowerShell" and selected "Run program of batch file" option
4) Click "Next"
4) At step 2 of job properties wizard,
under "Command line:" - selected as "E:\Program Files\t\DataDel.bat" (without quotes)
under "Start in:" - select as "E:\Program Files\t" (without quotes)
5) At step 3, click "Finish"
Ran the jon in normal mode, and Job log shows that "Job started", but never finishes and nothing else recorded in the event log.
I am running this on OS Windows 2008 R2 (64 bit) machine.
I have opened 24x7 scheduler in Administrator mode.
|
|
Sat Mar 16, 2013 11:50 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
I see several issues, mostly problems with missing or incorrect quotes.
Lety's change the batch file content to
 |
 |
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe "E:\Program Files\t\DataDel.ps1" |
In the job properties, let's enter he the command line as
cmd /C "E:\Program Files\t\DataDel.bat" > E:\DataDel.log
In the startup directory enter C\Windows\system32\WindowsPowerShell\v1.0
Run the job, and if it doesn't work, post here the content of E:\DataDel.log file
|
|
Sun Mar 17, 2013 9:44 pm |
|
 |
kishorepi
Joined: 11 Mar 2013 Posts: 10 Country: United States |
|
|
|
Got the following error in log file:
3 Sun Mar 17 22:46:20 EDT 2013 Sun Mar 17 22:46:20 EDT 2013 12 PSDataDel Job definition incomplete. Missing or invalid START_IN property value.
It didn't generate the log file.
Thanks for helping with this.
|
|
Sun Mar 17, 2013 10:48 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
The error indicates that "E:\Program Files\t" value specified for the Startin directory is an invalid path. Please verify this path is correct and accessible to the account running 24x7 Scheduler.
|
|
Mon Mar 18, 2013 8:14 am |
|
 |
kishorepi
Joined: 11 Mar 2013 Posts: 10 Country: United States |
|
|
|
I gave the startup directory as "C\Windows\system32\WindowsPowerShell\v1.0" as you suggested.
I didn't understand "accessible to the account running 24x7 Scheduler".
- I logged on using my own credentails and i am administrator on the box
- I also tried running the scheduler As admin, it didn't work with that either
Let me know if i need to set the user somewhere so that 24x7 schduler runs with that particular account.
|
|
Mon Mar 18, 2013 5:48 pm |
|
 |
|