SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Cannot execute powershell script
Goto page 1, 2  Next
 
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite View previous topic
View next topic
Cannot execute powershell script
Author Message
kishorepi



Joined: 11 Mar 2013
Posts: 10
Country: United States

Post Cannot execute powershell script Reply with quote
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 View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7838

Post Reply with quote
Try running 24x7 in Run as Administrator mode
Mon Mar 11, 2013 6:02 pm View user's profile Send private message
kishorepi



Joined: 11 Mar 2013
Posts: 10
Country: United States

Post Reply with quote
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 View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7838

Post Reply with quote
Open command prompt in Run as Admin mode, then
C:
cd C:\24x7
master.bat
Mon Mar 11, 2013 8:05 pm View user's profile Send private message
kishorepi



Joined: 11 Mar 2013
Posts: 10
Country: United States

Post Reply with quote
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 View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7838

Post Reply with quote
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

Code:
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 View user's profile Send private message
kishorepi



Joined: 11 Mar 2013
Posts: 10
Country: United States

Post Reply with quote
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 View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7838

Post Reply with quote
the previous sample for FileDir was incorrect, please try this one

Code:
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 View user's profile Send private message
kishorepi



Joined: 11 Mar 2013
Posts: 10
Country: United States

Post Reply with quote
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 View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7838

Post Reply with quote
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 View user's profile Send private message
kishorepi



Joined: 11 Mar 2013
Posts: 10
Country: United States

Post Reply with quote
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 View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7838

Post Reply with quote
I see several issues, mostly problems with missing or incorrect quotes.

Lety's change the batch file content to

Code:
%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 View user's profile Send private message
kishorepi



Joined: 11 Mar 2013
Posts: 10
Country: United States

Post Reply with quote
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 View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7838

Post Reply with quote
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 View user's profile Send private message
kishorepi



Joined: 11 Mar 2013
Posts: 10
Country: United States

Post Reply with quote
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 View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.