Create Pull Request
| Date | Scan | Status | Result |
|---|---|---|---|
| 2025-07-12 23:44 | #41 | cancelled |
Biased
|
| 2025-07-12 00:58 | #8 | cancelled |
Clean
|
| 2025-07-10 05:06 | #7 | processing |
Clean
|
| 2025-07-09 23:22 | #6 | cancelled |
Clean
|
$Cred = Get-AutomationPSCredential -Name "MyCredential" $Computer = Get-AutomationVariable -Name "ComputerName" Restart-Computer -ComputerName $Computer -Credential $Cred
# Ensures you do not inherit an AzContext in your runbook
Disable-AzContextAutosave -Scope Process
# Connect to Azure with user-managed-assigned managed identity. Replace <ClientId> below with the Client Id of the User Managed Identity
$AzureContext = (Connect-AzAccount -Identity -AccountId <ClientId>).context
# set and store context
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile
$AzureContext
# Get all VM names from the subscription
Get-AzVM -DefaultProfile $AzureContext | Select Name
### Sign your runbooks using the certificate With the Hybrid Runbook Workers configured to use only signed runbooks, you must sign runbooks that are to be used on the Hybrid Runbook Worker. Use the following sample PowerShell code to sign these runbooks.
# Ensures you do not inherit an AzContext in your runbook
Disable-AzContextAutosave -Scope Process
# Connect to Azure with system-assigned managed identity
$AzureContext = (Connect-AzAccount -Identity).context
# set and store context
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile
$AzureContext
# Get all VM names from the subscription
Get-AzVM -DefaultProfile $AzureContext | Select Name
# Ensures you do not inherit an AzContext in your runbook
Disable-AzContextAutosave -Scope Process
# Connect to Azure with system-assigned managed identity
$AzureContext = (Connect-AzAccount -Identity).context
# set and store context
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile
$AzureContext
# Get all VM names from the subscription
Get-AzVM -DefaultProfile $AzureContext | Select Name
## Work with signed runbooks on a Windows Hybrid Runbook Worker You can configure a Windows Hybrid Runbook Worker to run only signed runbooks. > [!IMPORTANT] > Once you've configured a Hybrid Runbook Worker to run only signed runbooks, unsigned runbooks fail to execute on the worker. > [!NOTE] > PowerShell 7.x does not support signed runbooks for Windows and Linux Hybrid Runbook Worker. ### Create signing certificate The following example creates a self-signed certificate that can be used for signing runbooks. This code creates the certificate and exports it so that the Hybrid Runbook Worker can import it later. The thumbprint is also returned for later use in referencing the certificate.
### Import certificate and configure workers for signature validation Copy the certificate that you've created to each Hybrid Runbook Worker in a group. Run the following script to import the certificate and configure the workers to use signature validation on runbooks.