header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Run Powershell script in schedule task background
Last Post 17 May 2011 02:12 AM by Alagar. 9 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
RicardoUser is Offline
New Member
New Member
Posts:3
Avatar

--
25 Feb 2010 10:33 AM
    Hi

    I need to run one ps script without opening the powershell console i have configured a schedule task with the following parameters: powershell path\ResolveAlertsCPUSCOM.ps1 -rms xxxx -alertName 'yyyy'.

    The script runs but open the console of powershell.

    How can i run the script without open the console?

    Thks.
    Ricardo Marques
    SureshUser is Offline
    New Member
    New Member
    Posts:31
    Avatar

    --
    25 Feb 2010 01:02 PM
    What is the command line in your SchduleTask?

    try this:
    Powershell.exe -WindowStyle "Hidden" Script.ps1 > logit.log 2>&1

    Checkout "powershell /?" for more help!
    RicardoUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    25 Feb 2010 02:43 PM
    Hi

    The command in schedule task is: powershell -WindowStyle "Hidden" D:\Processos\SCOMCloseAlertsCPU\ResolveAlertsCPUSCOM.ps1 -rms xxx -alertName 'xxx- Top Process' like you say.
    The window open but close immediately and the task is running, to be perfect the window should never open.
    I use windows powershell v2.
    I can run silent dos command in vbscript without open any window when i configure that script running from schedule task it is possible to do the same with powershell?

    Thks.
    Ricardo Marques
    SureshUser is Offline
    New Member
    New Member
    Posts:31
    Avatar

    --
    25 Feb 2010 10:00 PM
    OK, Which OS are you running this on?
    RicardoUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    26 Feb 2010 03:47 AM
    Os- Windows 2003 Sp2
    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1646
    Avatar

    --
    26 Feb 2010 04:28 AM
    There was a brief discussion about this in a private mailing list. Under some circumstances, it might be nearly impossible to truly hide powershell.exe from doing some kind of popup.

    Think of it this way, powershell.exe needs to actually open/run to first determine that it should actually be closed...

    I might do more stuff around this problem next week and maybe log a Microsoft Connect bug.
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    26 Feb 2010 05:54 AM
    It is possible to completely supress the window from appearing, however, you need to wrap the invocation of your script with a Visual Basic Script:

    ' Argument from command-line
    strFile = WScript.Arguments(0)

    Dim objShell, objFSO, objFile

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

    If objFSO.FileExists(strFile) Then ' Check to see if the file exists
    Set objFile = objFSO.GetFile(strFile)
    strCmd = "powershell -nologo -command " & Chr(34) & "&{" & objFile.ShortPath & "}" & Chr(34) ' Chr(34) is ""
    objShell.Run strCmd, 0 ' 0 hides the window
    Else
    WScript.Echo "ERROR: " & strFile & " does not exist." ' Display error message if file does not exist
    WScript.Quit
    End If

    Copy that into a text file, and save it as a .vbs file, then you can use it as such:

    cscript "PathToMyVbsScript.vbs" "PathToMyPsScript.ps1"
    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1646
    Avatar

    --
    26 Feb 2010 06:05 AM
    Posted By GWHowarth88 on 26 Feb 2010 05:54 AM
    It is possible to completely supress the window from appearing, however, you need to wrap the invocation of your script with a Visual Basic Script:

    ' Argument from command-line
    strFile = WScript.Arguments(0)

    Dim objShell, objFSO, objFile

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

    If objFSO.FileExists(strFile) Then ' Check to see if the file exists
    Set objFile = objFSO.GetFile(strFile)
    strCmd = "powershell -nologo -command " & Chr(34) & "&{" & objFile.ShortPath & "}" & Chr(34) ' Chr(34) is ""
    objShell.Run strCmd, 0 ' 0 hides the window
    Else
    WScript.Echo "ERROR: " & strFile & " does not exist." ' Display error message if file does not exist
    WScript.Quit
    End If

    Copy that into a text file, and save it as a .vbs file, then you can use it as such:

    cscript "PathToMyVbsScript.vbs" "PathToMyPsScript.ps1"
    Yes, I think that worked fine with PowerShell v1, but when I did some testing with v2 with the Task Scheduler (on XP SP3), a DOS command *still* appeared.

    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    02 Mar 2010 09:33 AM
    We're currently running several powershell scripts using:
    powershell.exe &'Script_name.ps1'

    also, try run the script above with wscript instead of cscript
    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    AlagarUser is Offline
    New Member
    New Member
    Posts:1
    Avatar

    --
    17 May 2011 02:12 AM
    Excellent script!

    i was searching a lot in the net and scratching my head to find a solution in the last two days.

    For me it is working fine thanks a lot!

    Regards
    Alagar
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer