Good Afternoon,
Been troubleshooting a weird bug after upgrading to 2.9.1 where I have an API/Endpoint that basically calls another script with a few params.
I think its a two part problem. One being with the #Requires -Module ActiveDirectory and or using Invoke-UAScript -Credential
New-PSUEndpoint -Url "/offboard_broken" -Method "Get" -Endpoint {
Connect-UAServer -ComputerName 'http://localhost:5000' -AppToken $AdminToken
#region Offboard script section
$OffboardScriptParams = [ordered]@{
Script = 'Offboard.ps1'
UserAccount = "Dummy.Account@email.com"
Credential = $(Get-UAVariable -Name "SomeCreds")
}
Invoke-UAScript @OffboardScriptParams | Tee-Object -Variable OffboardJob | Wait-UAJob
$CurrentJob = Get-UAJob -Id $OffboardJob.Id
$JobOutput = $(Get-UAJobOutput -Job $CurrentJob).Data
$ReturnData = @{
JobNumber = $($CurrentJob.id)
data = $JobOutput
} | ConvertTo-Json
$ReturnData
} -Authentication -Role @('Administrator')
Hitting that endpoint returns the following:
{
"data": "The script 'Offboard.ps1' cannot be run because the following modules that are specified by the \"#requires\" statements of the script are missing: ActiveDirectory.",
"JobNumber": 80
}
After commenting out the credential in the dictionary and removing the #Requires -Modules ActiveDirectory from the script that the api is invoking.
New-PSUEndpoint -Url "/offboard_working" -Method "Get" -Endpoint {
Connect-UAServer -ComputerName 'http://localhost:5000' -AppToken $AdminToken
#region Offboard script section
$OffboardScriptParams = [ordered]@{
Script = 'Offboard.ps1'
UserAccount = "Dummy.Account@email.com"
#Credential = $(Get-UAVariable -Name "SomeCreds")
}
Invoke-UAScript @OffboardScriptParams | Tee-Object -Variable OffboardJob | Wait-UAJob
$CurrentJob = Get-UAJob -Id $OffboardJob.Id
$JobOutput = $(Get-UAJobOutput -Job $CurrentJob).Data
$ReturnData = @{
JobNumber = $($CurrentJob.id)
data = $JobOutput
} | ConvertTo-Json
$ReturnData
} -Authentication -Role @('Administrator')
Hitting the working endpoint it returns the following module (which is expected) and you can see it returned the correct modules (get-module).
Another weird thing that I noticed was if the script has a #Requires -Module ActiveDirectory at the top I get the following even when I comment out the #Credentials from the api/endpoint
This has been working since version 1.5.4 - There is no error messages in the logs.
Product: PowerShell Universal
Version: 2.9.1