我正在尝试构建Azure自动化Runbook来解锁本地AD帐户。解锁帐户后,我想向具有API的ITSM应用程序提交票证。我能够在Windows PowerShell中在服务器上创建调用,并获得200的返回代码。
但是,当我从Azure自动化运行它时,我收到错误代码400错误请求。有关为什么我可以使用Windows PowerShell在服务器上进行调用而不在混合工作者上使用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
}
我遇到的问题实际上是我们的防火墙和代理问题。这些服务器无法与建议的所有Azure / O365 URL进行通信。一旦我们将所有URL列入白名单,我就能够与我的内部应用程序通信。