locked
SCCM2012R2 Script/batch file deployment to actually run, and not install? Please HELP. RRS feed

  • Question

  • Hi

    I have SCCM2012R2 and i want to do a weekly scan with endpoint protection every saturday on some computers. I want this to happen during night, and by night the computers are powered down.

    I started off by doing a device collection. I invited the computers i wanted to scan. I gave that group a scheduled task. Which was to do a endpoint full scan every saturday 2am.

    After that i made a batch file and a vbs script. They both do the same thing they shut the computer down after 3 hours. With this simple line: "shutdown.exe -s -t 10800".

    After that i looked into if you could deploy script/batch files. I found a few pages that said you could and followed them. Most of them told me to create a new application "Package". And then pick the batch/script file. Another thing i noted was that i couldnt set the deadline date with package-deploment. With application deployment you can easily set a deadline. 

    Long story short ive tried this and it didn't work. The computers powered on thanks to the magic package from the deployment. And later they began to fullscan with endpoint protection thanks to the scheduled task within the group policy. After 3 hours the computer should power down. If the script actually ran. But the computers didn't shutdown so the script never ran....

    note: I can't enable sleepmode, not a possibilty.

    tl:dr; Everything worked except the script which didn't run that caused the computers to stand idle the whole night.

    If someone can help me make a deployment so that my script actually is being executed by the computers i would greatly appreciate it.

    Sorry for my bad English
    All answer are appreciated!



    • Edited by Einherien Wednesday, October 28, 2015 12:55 PM
    Wednesday, October 28, 2015 12:40 PM

Answers

  • Just curious, how have you configured the re-run behavior of the deployment under the Scheduling tab? If it's only running once on a particular device, configure the deployment to have a re-run behavior of "Always rerun".

    Nickolaj Andersen | www.scconfigmgr.com | @NickolajA

    • Proposed as answer by Nickolaj AndersenMVP Wednesday, November 4, 2015 11:49 AM
    • Marked as answer by Einherien Monday, November 9, 2015 10:37 AM
    Tuesday, November 3, 2015 1:15 PM

All replies

  • "Another thing i noted was that i couldnt set the deadline date with package-deploment. "

    That's correct, but that doesn't mean you can't do the same thing. Package/Program Deployments have schedules that define at what time you would like the agent to initiate them. This is equivalent to a deadline except that you can define multiple schedules as well as recurring schedules. That's why packages/programs are preferred for tasks like the one you've described.

    When deploying the package/program, what schedule did you assign to it (if any)?


    Jason | http://blog.configmgrftw.com | @jasonsandys

    Wednesday, October 28, 2015 1:28 PM
  • note: I can't enable sleepmode, not a possibility.


    I have to ask, why can't you enable Sleep mode? Sleep mode make a lot more sense to shut down computers than trying to run a batch file to shut them down.

    Garth Jones | My blogs: Enhansoft and Old Blog site | Twitter: @GarthMJ

    Wednesday, October 28, 2015 2:46 PM
  • Alright thanks Jason!

    So "Occurs on...." in Assignment schedule is equivalent to the deadline?

    I think it looked like this
    https://gyazo.com/1c9b5a6dcc6d4aa72b221e81b09ea154

    • Edited by Einherien Wednesday, October 28, 2015 3:02 PM
    Wednesday, October 28, 2015 3:02 PM
  • Hi Garth

    The reason why we can't have sleep mode enabled on our domain is because alot of our clients do heavy calculations with different programs. these calculations can take from 8 hours to 3 days. The computer doesn't recognise these calculations and will enter sleepmode. While in sleepmode some of the calculations just freezes. So the next morning when klient his calculations are done its just about the same as it was when he left.
    Wednesday, October 28, 2015 3:02 PM
  • I wouldn't say they are equivalent, but the end result is the same and your screenshot accurately reflects configuring the deployment to run at the time listed which is Oct 28th at 3:54 PM. This will thus run one time and catch up a single time if needed if for some reason the system was off. To check if it did run, you need to examine execmgr.log on the client.

    Jason | http://blog.configmgrftw.com | @jasonsandys

    Wednesday, October 28, 2015 5:26 PM
  • I vaguely remember there is a way to stop a computer from sleeping, if there is a app that is running. But I can't find it... Maybe you will have better luck.


    Garth Jones | My blogs: Enhansoft and Old Blog site | Twitter: @GarthMJ

    Thursday, October 29, 2015 2:40 PM
  • Hmm it didn't seem to run. Does it matter if its a vbs-script or a batch in the package iam deploying?

    Anyway iam trying to run a script which shuts down the computers. Maybe its easier with a group policy?

    Thanks alot for helping me understand.

    @Garth

    Alright, ill search around see if i can find anything. Thanks for your effort.

    • Edited by Einherien Monday, November 2, 2015 9:28 AM
    Monday, November 2, 2015 6:34 AM
  • Hmm it didn't seem to run. Does it matter if its a vbs-script or a batch in the package iam deploying?

    ConfigMgr simply runs the command-line you give it and has no way or need to make any distinctions. If it's not running, then the client doesn't have the policy, you haven't hit your scheduled time yet, or the system is outside of a configured maintenance window.

    Jason | http://blog.configmgrftw.com | @jasonsandys

    Monday, November 2, 2015 9:21 PM

  • Okay i got it to shutdown, i created a new package and inside my script i think i had to have this
    @ECHO OFF
    IF NOT "%PROCESSOR_ARCHITEW6432%"=="AMD64" GOTO native
      ECHO "Re-launching Script in Native Command Processor..."
      %SystemRoot%\Sysnative\cmd.exe /c %0 %*
      EXIT
    :native
    ECHO "Running Script in Native Command Processor..."

    The only thing now is that it only shuts off if i login. I am certain i chose to "whether or not a user is logged in".

    EDIT; 
    Alright it worked once, then i tried again and it didn't work. I had the exact same settings. I made sure both the deployments were in maintaince schedule. 

    Evertime i deploy the computers starts. But only one time the actual batch ran. I had the exact same deploy settings.

    Why would it only work once?

    Thanks for all the help guys appreciate it.
    • Edited by Einherien Tuesday, November 3, 2015 12:28 PM
    Tuesday, November 3, 2015 9:43 AM
  • Just curious, how have you configured the re-run behavior of the deployment under the Scheduling tab? If it's only running once on a particular device, configure the deployment to have a re-run behavior of "Always rerun".

    Nickolaj Andersen | www.scconfigmgr.com | @NickolajA

    • Proposed as answer by Nickolaj AndersenMVP Wednesday, November 4, 2015 11:49 AM
    • Marked as answer by Einherien Monday, November 9, 2015 10:37 AM
    Tuesday, November 3, 2015 1:15 PM
  • Hi Nickolaj
    Iam thankfull for your interest in helping me.

    I had it set on "Rerun if failed previous attempt".
    Do you think that might be the solution to my first problem?

    I deleted the package since it only worked 1 time. Then i made a new package with the exact same settings and paths as my previous package. The exact same thing. It worked once. 

    The computers poweron, after that they run the script and eventually powers down after x seconds. Theres a slight problem though. In order for them to shutdown i have to be logged in.
    Even though ive checked the (program can run: "Whether or not a user is logged on")

    So basically my two problems are
    1. My deployment only runs the script ones. After that it only starts the computers.
    2. For the computers to get shutdown i need to be logged in as a user.

    Any answer is appreciated.




    • Edited by Einherien Tuesday, November 3, 2015 2:23 PM
    Tuesday, November 3, 2015 2:18 PM
  • I vaguely remember there is a way to stop a computer from sleeping, if there is a app that is running. But I can't find it... Maybe you will have better luck.


    Garth Jones | My blogs: Enhansoft and Old Blog site | Twitter: @GarthMJ

    This is the one I use (Insomnia):

    http://dlaa.me/blog/post/9901642

    It works perfectly.


    EDIT: For context, I use this so I can keep sleep enabled on my machines. I was given a business requirement that all machines be awake from 6-9AM so users don't have to take the extra time to wake the machines up. I push a script that runs this tool to keep the machines awake during the required timeframe and then once the window closes they're allowed to sleep.

    Perhaps you could do something similar.


    Tuesday, November 3, 2015 2:25 PM
  • Thanks alot Mike
    Ill be sure to look into it. As soon as i get this done with this.

    Iam thankfull for your help.


    • Edited by Einherien Wednesday, November 4, 2015 6:27 AM
    Wednesday, November 4, 2015 6:26 AM
  • Alright Nickolaj

    I tried using your "Always rerun". It worked, thanks alot!

    Now i only have to figure out my second problem. Why it only runs the script when i login.
    • Edited by Einherien Wednesday, November 4, 2015 11:48 AM
    Wednesday, November 4, 2015 11:47 AM
  • For how long are you waiting until you login? The ConfigMgr agent is a delayed startup service, and it could take up to 5 minutes.

    Could you upload the execmgr.log for us to take a look at it?


    Nickolaj Andersen | www.scconfigmgr.com | @NickolajA

    Wednesday, November 4, 2015 11:50 AM
  • Hi Nickolaj i won't be back until monday. 
    I deploy on 2 test computers. Computer x is poweredOff. Computer z is powered on and logged in.

    So when i deploy:
    x -> PowersOn ->GetsToLoginScreen -> NothingHappens

    z -> GetsPrompt(Computer will shutdown in 5minutes) -> Shutsdown

    As soon as i login on computer x  i get the same prompt. saying that my computer will shutdown in 5 minutes (Which ive sat the script to be.)

    About execmgr.log, i will upload as soon as i can, monday that is.

    If you dont care anymore by then, thanks alot for you help Nickolaj
    Wednesday, November 4, 2015 3:20 PM
  • Alright iam not sure if this was the thing you were looking for.
    I only took today.

    https://drive.google.com/file/d/0ByyFfqlmvmPRVlB4eGF3QkMyc1E/view?usp=sharing

    Iv'e ran the deployment on computer 
    208 and 179

    208 was powered off. When i ran the deployment 208 powered on, and got to login screen.

    179 was logged in. When i ran the deployment 179 took about 3 minutes then gave me a prompt saying it will shutdown in 5 minutes. I waited around 4 minutes then cancelled the shutdown. After i cancelled the shutdown i waited 2 minutes more and then i logged in on computer 208. When i logged in it took about 3 minutes the same as 179 and then 208 said that it was going to shutdown in 5 minutes. I cancelled that aswell.

    Its like it doesn't listen to the - Run:"Whether or not a user is logged in"

    Previous days ive been waiting for up 25 minutes. When it's supposed to shutdown in 5. The logged in computer listens and shutdowns after 5. But the other doesn't. As soon as i login on the other it takes about 3 min then gives me the prompt that it will shutdown in 5.

    Thanks again Nickolaj
    • Edited by Einherien Monday, November 9, 2015 8:10 AM
    Monday, November 9, 2015 7:46 AM
  • How's the Environment tab of your Program configured?

    Was the execmgr.log from the system where it didn't run the batch file?


    Nickolaj Andersen | www.scconfigmgr.com | @NickolajA

    Monday, November 9, 2015 8:43 AM
  • My environment for program


    Well it ran the batch files on both computers but i had to be inlogged on a user for it to run.
    Do you want me to not login and then send you the execmgr.log?

    Thanks
    • Edited by Einherien Monday, November 9, 2015 8:48 AM
    Monday, November 9, 2015 8:48 AM
  • The Environment tab looks correct to me.

    Yes, that might be helpful.


    Nickolaj Andersen | www.scconfigmgr.com | @NickolajA

    Monday, November 9, 2015 9:45 AM
  • Hi Nickolaj

    It works.

    I told you i waited 25 mins before. And i did but the problem was that it was set to re-run if previous failed. So now i tried again with your "always rerun" and it worked. I just have to wait for the computers to start up properly. it took about 8 minutes for 1 computer and 12 for the other.

    ive tested this 3 times now and it worked every single time. It just takes some time.

    Thanks alot Nickolaj i really appreciate your help.
    Thanks the other guys aswell, Garth, and Jason.

    Monday, November 9, 2015 10:37 AM
  • That's great! Remember to mark my reply as the answer for this post :)

    Nickolaj Andersen | www.scconfigmgr.com | @NickolajA

    Monday, November 9, 2015 10:38 AM
  • Yes i think i did :) Is there any other way i can credit you? Like points or medals?
    Monday, November 9, 2015 10:47 AM
  • Haha, no I don't think so. I'm just happy to help :)

    Nickolaj Andersen | www.scconfigmgr.com | @NickolajA

    Monday, November 9, 2015 11:07 AM