我正在尝试构建Azure自动化运行手册以解锁本地AD帐户。帐户解锁后,我想向具有API的ITSM应用程序提交票证。我能够在Windows PowerShell中的服务器上创建呼叫,并获得200的返回码。
但是,当我从Azure自动化运行它时,收到错误代码400错误的请求。关于为什么我可以使用Windows PowerShell在服务器上进行呼叫但不能在Hybrid Worker上进行Azure自动化的任何想法?
Custom_ITSM_API_Module的模块是一个本地开发的模块,可以在我尝试过的所有地方使用。它在我的开发计算机(Windows PowerShell)和混合工作服务器(Windows PowerShell)上有效,但在使用Azure自动化时不起作用。
代码:
Param
([object]$WebhookData) #this parameter name needs to be called WebHookData otherwise the webhook does not work as expected.
$VerbosePreference = 'continue'
Import-Module ActiveDirectory
Import-Module "Custom_ITSM_API_Module"
#region Verify if Runbook is started from Webhook.
# If runbook was called from Webhook, WebhookData will not be null.
if ($WebHookData){
# Collect properties of WebhookData
$WebhookName = $WebHookData.WebhookName
$WebhookHeaders = $WebHookData.RequestHeader
$WebhookBody = $WebHookData.RequestBody
# Collect individual headers. Input converted from JSON.
$From = $WebhookHeaders.From
$RequestData = (ConvertFrom-Json -InputObject $WebhookBody)
Write-Output -InputObject ('Input: {0}' -f $RequestData )
Write-Output ('WebhookBody: {0}' -f $WebhookBody)
Write-Output -InputObject ('Runbook started from webhook {0} by {1}.' -f $WebhookName, $From)
$User = Get-ADUser $RequestData.SamAccountName -Properties *
If($User.SamAccountName.count -ne 1 ){
throw "Found $($User.SamAccountName.count) user(s). Please make sure this user is unique"
}
else{
Write-Output "Unlocking User"
Unlock-ADAccount -Identity $User
$RanByEmployeeID = $RequestData.RanByEmployeeID
$Runby = Get-ADUser -Filter {EmployeeID -eq $RanByEmployeeID} -Properties EmployeeID
$Description = "User Unlcoked<br>EmployeeID: $($User.EmployeeID)<br>SamAccountName: $($User.SamAccountName)<br>Unlocked at: $((Get-Date).ToString())"
Write-Custom_ITSM_API_ModuleTicket -Title "Unlocked User $($User.Name)"-Description $Description
}
}
else{
Write-Error -Message 'Runbook was not started from Webhook' -ErrorAction stop
}
答案 0 :(得分:0)
我遇到的问题实际上是防火墙和代理的问题。这些服务器无法与建议的所有Azure / O365 URL通话。将所有URLS列入白名单之后,我就可以与内部应用程序进行通话了。