Scheduler Defies Logic

Product: PowerShell Universal
Version: 3.4.1

When I run a job via the “Scripts” are of PSU my job runs fine. It matches on the IF statement and exits as it should. When I run the Script via the Scheduler it does NOT match the IF condition. I tried logging into my Windows 2016 server and running the script as myself and the service account user tied to PSU. When I debug both match true and have the same data in the variables.

[string]$netboxCompletedTagName = "ap-mgmgt-subnet-converted"

# Looks up the store's site in NetBox and returns the object
# Will throw an error if it receives more or less than 1
$netboxStore = Get-DSGNetboxSiteByStoreNumber -store_number $storenumber
if ($netboxStore.count -ne 1){write-error "netboxStore did not return 1 object"}
[array]$siteTags = $netboxStore.results.tags.slug

# Exits the script if -netboxCompletedTagName is found on the site object in NetBox
if ( $netboxCompletedTagName -in $siteTags) {
    Write-Warning "$($netboxCompletedTagName) NetBox Site tag found on NB store $($netboxStore.results.name)... exiting"
    Write-host $siteTags
    return
}
else {
    Write-Output 'hit else statement in ( $netboxCompletedTagName -in [array]$netboxStore.results.tags.slug)'
    Write-Output $siteTags
    return
}

Is your schedule set to the same environment as when you run the script manually?

Yes. The are both using 7.2.6. I did a test run both ways to verify.

I created a master script that called the script with the issue above. I ran it ad hoc and scheduled and both were successful. This is how I plan to run the job in site groups so that part is encouraging. I still don’t understand how running an the job individually/scheduled can produce a condition where a true expression evaluates as false. One thing that was different is I used a simple schedule for my master job and a cron trigger for the one with the issue. All jobs still run when when they were scheduled, so maybe that is a moot point.