@Taranjeet Malik , Thank you for your question. The following information should help clarify the usage scenarios of "Hybrid Worker Credential" and "Get-AutomationPSCredential"
- By Default, Hybrid jobs run under the context of System Account. When you select the option as you have in the screenshot of question, the runbook script is run under the account that you select. It is similar to using "Shift+Right Click" for launching any application in Windows, through which you can launch an application with a different user account than through the user account used to log-in:
In this scenario, if you are not using any cmdlet with "credential" parameter, the account selected is used for authentication.
- When you use Get-AutomationPSCredential to get credential stored as Automation Asset, you get this credential in a variable. It will not change the context of the script itself. This credential can be used with cmdlets which supports supplying such parameter so that that particular cmdlet uses the credential retrieved using
Get-AutomationPSCredential
cmdlet, and other part of script still uses the default account or the hybrid worker account. For example, consider a hypothetical script as below:
#<Some other lines in script>
$Cred = Get-AutomationPSCredential -Name "MyCredential" $Computer = Get-AutomationVariable -Name #---------Line 1
"ComputerName" Restart-Computer -ComputerName $Computer -Credential $Cred #---------------Line 2
#<other part of script>
In this sample, if you have selected a Hybrid runbook worker account, everything would use that account as context. But the cmdlet in #line2 uses the credential stored as Automation credential which is being passed using the -credential
parameter.
Thus, you do not need multiple hybrid worker group, if you want to use credential as shown the hypothetical script above.
Hope this helps.
If the answer did not help, please add more context/follow-up question for it, and we will help you out. Else, if the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.