Etapa1
EstousolicitandoapenasoIDdousuárioparaesteRunbook.UserID(datatype:String)
Etapa2
EuprecisodeterminaroIDdoRunbook,afimdepuxaroSIDemumaconsultaSQLposterior.AquiestáaconsultaSQLqueretornaoIDdotrabalho.
SELECTPOLICYINSTANCES.JobIDFROMPOLICYINSTANCESINNERJOINACTIONSERVERSONPOLICYINSTANCES.ActionServer=ACTIONSERVERS.UniqueIDWHERE(POLICYINSTANCES.ProcessID='{ActivityProcessfrom"Start"}') AND
(ACTIONSERVERS.Computer = '{Runbook Server Name from "Start"}') AND (POLICYINSTANCES.Status IS NULL)
This should return something like the following GUID: {AFA8BF28-1937-4DAE-A160-30FF130AE6CD}.
Etapa 3
Depois de ter esse GUID, você precisa retirá-lo das chaves. Eu uso o seguinte script powershell para fazer isso:
$a = '{Full line as string with fields separated by ':' from "Get Runbook Job ID"}'
Write-Host $a.Trim('{}')
This should return the GUID without {} AFA8BF28-1937-4DAE-A160-30FF130AE6CD
Etapa 4
Quando tivermos o GUID, podemos procurar o Runbook adequado e pegar o SID de outra tabela SQL do usuário que iniciou o Runbook:
Select Jobs.CreatedBy
From [Microsoft.SystemCenter.Orchestrator.Runtime].Jobs AS Jobs
INNER JOIN POLICIES ON Jobs.RunbookId = POLICIES.UniqueID
Where Jobs.Id = '{PS Execution 01 Results {with Write-Host) from "Remove {} from Runbook Job GUID"}'
Isso retornará o SID da conta do usuário, algo assim: S-1-5-21-1855722787-1516450073-351226437-1111
Etapa 5
Eu corro o seguinte script Powershell para obter o ID do usuário, endereço de e-mail, etc.
$objSID = New-Object System.Security.Principal.SecurityIdentifier("{Full line as string with fields separated by ';' from "Get the SID of the user that executed this Runbook"}")
$objUser = $objSID.Translate( [System.Security.Principal.NTAccount])
$result = $objUser.Value
$UserName = $result.TrimStart("YOUR-DOMAIN-NAME\")
Etapa 6
Agora você pode obter todos os tipos de informações do usuário que executou o Runbook.