6 Replies Latest reply on Jun 21, 2017 5:41 AM by phoffmann

    Anyone using the local scheduler to run powershell scripts?

    Gjstewart Specialist

      As the title says..

       

      I have the local scheduler working launching as system but for some reason its not launching the script -

       

      am i missing something?  do you have bypass execution policy with local scheduler?

       

      REMEXEC1003=<qt/>%LDMS_CLIENT_DIR%\LocalSch.exe<qt/> /exe=%quote%powershell.exe%quote% /cmd=<qt/>C:\ProgramData\Get-Reboot_Status.ps1<qt/> /taskid=1003  /freq=600 /toe=logon /start=%quote%24 May 2017 08:03:32%quote%

        • 1. Re: Anyone using the local scheduler to run powershell scripts?
          phoffmann SupportEmployee

          Not usually using the local scheduler for this - I usually use the schduler side for it (along with Windows Actions) ...

           

          Bear in mind that Local Scheduler runs as LOCAL SYSTEM - so you may want to look at the machine policy in PowerShell .

          • 2. Re: Anyone using the local scheduler to run powershell scripts?
            Gjstewart Specialist

            Hey Paul - thanks

             

            I can see powershell.exe launch with the scheduler ( i had a separate task just launching the powershell.exe with no script ) but was not sure if the local scheduler could handle calling a script after.

             

            I am assuming it can as its definitely launched the main exe.

             

            I am fine with system - this is checking for pending reboots and writing the data to a custom field.

             

            So you are running a windows scheduled task?

            • 3. Re: Anyone using the local scheduler to run powershell scripts?
              phoffmann SupportEmployee

              No - I'm using a "Actions" package usually myself (as in "Software Distribution" type policy that runs every now & then) . But there's no "wrong" way ... whatever works for you & it's just a few lines of Powershell at the end of the day .

              • 4. Re: Anyone using the local scheduler to run powershell scripts?
                Gjstewart Specialist

                I see...

                 

                It is but as its reporting all different reasons for pending reboots and this could happen at any time - need it to be as real time as possible - i wanted to trigger it as a user logs on to update it everytime - actions are scheduled tasks right?

                 

                Or can you tie them into each log on? I might play with launching a bat file to launch the PS script or just the cmd /c powershell - was just curious if i was missing something -

                 

                thanks for responses!

                • 5. Re: Anyone using the local scheduler to run powershell scripts?
                  Gjstewart Specialist

                  For anyone wanting to do it you can do it like this... create a bat file which the local scheduler calls and have this as the contents..

                   

                  @ECHO OFF

                  PowerShell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -Command "Remove-Item c:\ProgramData\LocalSched -Type Directory -recurse -Force"

                  PowerShell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -Command "New-Item c:\ProgramData\LocalSched -Type Directory -Force"

                  PowerShell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -Command "Copy-Item '\\server\ldlogon\packages\powershell\LocalTasks\*' 'c:\ProgramData\LocalSched' -recurse -force"

                  PowerShell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -Command "Start-Sleep -sec 10"

                  PowerShell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -Command "& 'c:\ProgramData\LocalSched\Get-Reboot_Status.ps1'"

                  PowerShell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -Command "Start-Sleep -sec 10"

                  PowerShell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -Command "& 'c:\ProgramData\LocalSched\GatherUSB.ps1'"

                  PowerShell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -Command "Start-Sleep -sec 10"

                  "%programfiles%\LANDesk\LDClient\startasuser.exe" PowerShell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -Command "& 'c:\ProgramData\LocalSched\MapDrive.ps1'"

                   

                   

                  notice startasuser for when we wanted drive info...or anything pertinent to the user.

                  • 6. Re: Anyone using the local scheduler to run powershell scripts?
                    phoffmann SupportEmployee

                    Nice - thanks for the sharing!

                     

                    As an aside (since there's always at least 3 ways of doing essentially "the same thing" in LDMS) ... we do have a "Windows Actions Package" (which is Powershell) that you could use as a repeatable task for such things as well.

                     

                    Granted - that's based / run from the Core - so won't work if you've got offline laptops for instance - but it's something to be kept in mind as a more controllable policy option.