none
Query Runbook name to get GUID returns more than one GUID.

    Question

  • I am querying a list of Runbook names to return the GUID so I can use SCORunner.exe to start the Runbooks.  
    I have multiple environments that I do this in but a few environments and I do not understand why,
    I get more than one GUID returned from the QUERY and nonee of them seem to be useful in stopping the Runbook.

    Here is a part of my script"
    FOR /F "Tokens=*" %%f in (D:\StartRunbooks\manifests\RunBookEnvironment_manifest.txt) do call :GetRunbook %%f
    Got End

    :GetRunBook
    myRunBook=%1
    sqlcmd -S mySQLServer -d Orchestrator -i "D:\StartRunbooks\sql\GetRunbookGUIDs.sql" -s, -W -v runbookname=%myRunBook%>>D:\_BackfillAutomation\StartRunbooks\WorkArea\runBookResults.txt
    Goto END

    I then run a clean up script to make the output clean but without the correct GUID it Doesn't matter.

    Here is the SQL I am running in GetRunbookGUIDs.sql for each Runbook name passed

    Set NOCOUNT ON
    Select Distinct lower(POLICIES.UniqueID) as RunbookID,POLICIES.Name as "RunBookName"
    From POLICIES
    INNER JOIN OBJECTS  on POLICIES.UniqueID = OBJECTS.ParentID
    Where POLICIES.Name = '$(runbookname)' and policies.deleted = 0
    ORDER BY RunbookID

    I am getting this back instead of the Runbook GUID I need to Start the runbook.  
    I am getting multiple returns back each with a different GUID for the same Runbook name.

    RunbookID,RunBookName
    ---------,-----------
    043be57e-a69c-4be3-835b-26a79882a77b,Auto Refills Schedule
    1b16de2d-7e97-4793-9d56-6784f3263f02,Auto Refills Schedule
    2223acbd-349d-47a9-9dbf-f8563d2ee2fb,Auto Refills Schedule

    This is not isolated to just this one runbook. I get the same results for them all that I am querying.

    Any help or better way of doing this would be great.

    Mike

    Monday, April 18, 2016 9:00 PM

Answers