mysql - How to execute PowerShell script on Task Scheduler? -


I'm trying to execute my PowerShell script every 5 minutes to run. I tried to use Windows 7 Task Scheduler to run it but instead it opens my script on Notepad and does not include anything in my database

Below is my PowerHail V-2.0 script I do not believe that I have something wrong with my code (which I suspect) or there is no way that I can include it in my script to run it every 5 minutes, which Runs from 9 a.m. to 9 p.m.

Here's how I've scheduled it:

  Normal -------- Run only when the user is logged on the trigger - ------ Trigger: every day at 8h56am - Description: After every trigger, every 5 minutes again indefinable status: active actions ------- Action: Start the details of a program: Path to the script  

Thanks in advance! POWERSHELL (Excluding connection):

  function ping_getUser {# Get online information about local hard drives only when you are online at the computer {$ workstation_list $ workstation in foreign currency ) {$ Command = $ connection.CreateCommand (); $ Order Connection = $ connection; $ Command.CommandText = "Include workstation_assored (username, hostname, online) values ​​(@ username, @ hostname, @ position)"; ### =============================================== Values ​​assigned as ============== ### parameters ### ===================== == ======================================= $ hostname = $ workstation; $ Test_ping = Test-Connection -CaptainName Hostname -Cora1-AreationCheckLinkIntroduction; $ Position = [bowl] (test-connection $ hostname -quiet-count 1-index silentlycontent); #if get TRUE user name if ($ test_ping) {TRY {$ username = (Get-WMIObject -ComputerName $ hostname-Class Win32_ComputerSystem -ErrorAction stop | Select-object -ExpandProperty username); } Catch {Write-host "caught exception" - Front color red; Write - host "$ _" - red color red; } TRY {if ($ test_ping- and $ username) {$ username = $ username.split ("\"); $ Username = $ username [1]; Do not make $ Username; }} CAT {Write-host "Captured Exception" -Fast Color Red; Write - host "$ _" - red color red; } # If ping succeeds but no user is logged ($ test_ping- and -not $ username) # -eq "" {$ username = "no user"; }} #end if #if ping is not there, then the name of username is correct and for the position Falsei elseif (! $ Test_ping) {$ username = [DBNull] :: Value; } # And otherwise ### =========================================== ==================### Assign parameters with the appropriate standards ### =================== == ======================================== $ command.Parameters.Add (" User name ", $ username). Out-null $ command Parameter. Add ("hostname", $ hostname). Out-null $ command Parameter. Add ("@ position", $ position). Out-null ### ============================================ =================### Execute the command query ### ======================= ==================================== TRY {$ command.ExecuteNonQuery () | Out of naught; Write - host "successfully entered database"; } Catch {Write-host "caught exception" - Front color red; Write - host "$ _" - red color red; } ### ============================================== ===============### Clear parameter value ### ================================== =================================== $ command.Dispose () $ hostname = ""; $ Username = ""; $ Position = ""; $ Test_ping = ""; } Try #end} #Chat for each loop {Write-host "Exception caught" -AfmanCollar Red; Write - host "$ _" - red color red; } # $ Connection capture Stop it (); # Ping_test function ping_getUser #execute function  

Your scheduled task to powershell Exe should be called from a script file passed as an argument.

  powershell.exe -file c: \ path_to_your_script \ script.ps1  

The user under which executes the permissions required to execute scripts in the script All actions


Comments

Popular posts from this blog

Active Directory Authenticated Proxy Server with Squid or CNTLM -

java - Can't add JTree to JPanel of a JInternalFrame -

python - Calculate STD manually using Groupby Pandas DataFrame -