header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Running PS Scripts from Windows Task Manager
Last Post 09 Feb 2008 01:08 AM by halr9000. 7 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
moonroxUser is Offline
New Member
New Member
Posts:4
Avatar

--
09 Feb 2008 12:22 AM  

I have tried several methods and have failed to get the script to launch from windows task manager.

So far I can run the scripts directly and they work fine but if I put them in windows task manager they not only fail to run they give no error or message that they failed.  In all cases the script runs fine from being directly run or called but not from windows task manager.  In addition I am using allsigned as execution policy.

So Here is the methods I have tried.  Note.  most of these methods are posted on the web.

1.  Create PS Script and call from .cmd file with the following syntax: powershell -nologo -noninteractive -command "& {d:\scripts\powershellscript.ps1}"

2.  Put the above command directly into the gui window in windows task manager.

3.  Create PS Script and call from .vbs with the following syntax:

Dim objShell,objFSO,objFile

Set objShell=CreateObject("WScript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")

'enter the path for your PowerShell Script
strPath="d:\scripts\powershellscript.ps1"

'verify file exists
If objFSO.FileExists(strPath) Then
'return short path name
    set objFile=objFSO.GetFile(strPath)
    strCMD="powershell -nologo -command " & Chr(34) & "&{" &_
     objFile.ShortPath & "}" & Chr(34)
    'Uncomment next line for debugging
    'WScript.Echo strCMD
   
    'use 0 to hide window
    objShell.Run strCMD,0

Else

'Display error message
    WScript.Echo "Failed to find " & strPath
    WScript.Quit
   
End If

halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
09 Feb 2008 12:37 AM  
Excuse me for missing the obvious here but I'm not sure what your question is. Seems you may be overcomplicating things?

win+r, powershell -noprofile c:\tmp\test.ps1
ctrl-shift-esc, alt-f, n, powershell -noprofile c:\tmp\test.ps1

Works fine for me.

For the record, my restriction policy is unrestricted--could be related.
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
moonroxUser is Offline
New Member
New Member
Posts:4
Avatar

--
09 Feb 2008 12:42 AM  

I can execute all my PS script both from a command prompt and from the run line.  the issue is when I take the exact same command as on the run line and put it into task manager GUI.   it fails to run.

halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
09 Feb 2008 12:44 AM  
So, using my example,

works: win+r, powershell -noprofile c:\tmp\test.ps1
does not work: ctrl-shift-esc, alt-f, n, powershell -noprofile c:\tmp\test.ps1

?
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
moonroxUser is Offline
New Member
New Member
Posts:4
Avatar

--
09 Feb 2008 12:50 AM  

maybe I am not understanding your terminology.

I assume win+r = ?

From a runit.cmd script with powershell.exe -noprofile C:\pathto\ps.ps1   The script runs.

But from windows task manager the same script will not run.

moonroxUser is Offline
New Member
New Member
Posts:4
Avatar

--
09 Feb 2008 01:06 AM  
You were right. I was trying much too hard.
powershell -nologo -noprofile -noninteractive "d:\scripts\veritas_bch_monitor\veritas_bch_monitor.ps1"

This is what worked.
halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
09 Feb 2008 01:07 AM  
win+r = the global keystrokes to open the Run dialog
ctrl-shift-esc = same for the Task Manager

Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
09 Feb 2008 01:08 AM  
:)
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer