Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Add a computer to a schedule through CMD?

Is there a command to add a computer to a schedule?

Currently how I handle imaging is..

MDT images, and then using PSExec I kickoff a deployment to the local machine (incorporated in the task sequence).  The deployments are for a list of baseline packages (currently 1 packages with nested packages).  After watching the latest webcast the idea of having an auto-updating schedule I could remotely kick off, well that would be awesome.  My idea of how to handle this would be..

Add computer to schedule, kickoff schedule, delete computer from schedule.

But I can't seem to find a way to actually add a computer to a schedule.

0

Comments

9 comments
Date Votes
  • No, there are no commands for adding targets to a schedule. You can do it through the database, but be careful. Make sure you have a backup of your database before messing around with it.

    INSERT INTO Targets (TargetType, Name) VALUES ('Computer', 'YOUR COMPUTER NAME HERE');
    INSERT INTO ScheduleTargets (ScheduleId, TargetId) VALUES (ID OF YOUR SCHEDULE, ID OF THE TARGET THAT WAS CREATED IN THE LINE ABOVE);

    For example:

    INSERT INTO Targets (TargetType, Name) VALUES ('Computer', 'SULU');
    INSERT INTO ScheduleTargets (ScheduleId, TargetId) VALUES (1, 3);
    0
  • I'm curious, what is the ScheduleTargetId used for inside of the ScheduleTargets table?

    $sql = "pragma table_info(ScheduleTargets)

    $query = $sql | sqlite3.exe $db

    $query | Format-Table

    0|ScheduleTargetId|integer|1||1
    1|ScheduleId||0||0
    2|TargetId||0||0

     

    Similarly, I can inject settings into the database and check to make sure they are there, but they don't show up in the Schedule in the Depoy Console

    $sql = "SELECT * FROM ScheduleTargets WHERE ScheduleId = '31'";

    $query = $sql | sqlite3.exe $db

    $query | Format-Table

    643|31|999

     

    I had done an insert with a TargetId of 999 so I could control what the ID was programmatically and put it into the query for the ScheduleTargets insertion without having a secondary query to get it.

    0
  • ScheduleTargetId is an automatically generated primary key. That's why I only defined ScheduleId and TargetId in the INSERT.

    ScheduleId has to exist in the Schedules table and TargetId has to exist in the Targets table.

    0
  • That makes sense. Curious why the computer name I provided isn't showing up in the schedule in PDQ Deploy. Looks like it should be right and that I should be able to see it. I'd really like to have this as well, so if I can get this working it'd be awesome!

    0
  • Did you refresh the Deploy console or close and re-open it? It's possible I missed something, but I want to cover the easy stuff first :)

    0
  • Yup, I absolutely tried that a couple times. I think that TargetID needs to go somewhere else as well, but I've not found it yet, and to be honest, what I've done above is really most of the effort I have put forth thus far. Have too many irons in the fire today!

    0
  • This works for me:

    param(

    [string]$Target_Name=$(throw"Please specify a target."),
    [string]$Schedule_ID=$(throw"Please specify a Schedule ID.")

    )

    $Deploy_DB = "C:\ProgramData\Admin Arsenal\PDQ Deploy\Database.db"

    # Insert the target into the Targets table
    sqlite3.exe "$Deploy_DB" "INSERT INTO Targets (TargetType, Name) VALUES ('Computer', '$Target_Name');"

    # Retrieve the TargetId of the target we just inserted. The [-1] grabs the last result
    $Target_ID = ( sqlite3.exe "$Deploy_DB" "SELECT TargetId FROM Targets WHERE Name LIKE '$Target_Name';" )[-1]

    # Create the desired entry in the ScheduleTargets table
    sqlite3.exe "$Deploy_DB" "INSERT INTO ScheduleTargets (ScheduleId, TargetId) VALUES ($Schedule_ID, $Target_ID);"
    0
  • That's so freakin weird. That code does bupkis for me. It executes without errors. I've verified that the data is in the database correctly. Nothing in the schedule. So weird. I even bounced the background service. I'll keep poking it. I'm sure it's something on my end just acting funny. Your code is solid, and as you said it works on your end. Maybe I'm just crazy haha.

    0
  • So I went to lunch, came back, and looked in Deploy, and one of the schedules I was testing against has the computer I was using in it now. I even refreshed everything after running the script, but didn't see it. 

    Something refreshed, but I can't tell what.

    0