Forum Discussion

SikkuSamra's avatar
10 months ago

Batch PowerShell Script

Hello! 

I am running a batch PowerShell script in LogicMonitor. My intended purpose is to extract the end date SAML certificate of a Enterprise Application in my Azure environment. My Active discovery script runs perfectly. However when I test my collector script, it believes my ##WILDVALUE## is an empty string. When I poll for the data for my instance, it retrieves the correct value. However, No Data gets returned when I enable my instances. My WILDVALUE does not contain any of the invalid characters. 

My Datapoint is in the format of ##WILDVALUE##.key

$EnterpriseAppSingle = "##WILDVALUE##"
$EnterpriseApp = Get-AzAdServicePrincipal -ObjectID $EnterpriseAppSingle
$CertExpires = ($EnterpriseApp.PasswordCredentials.EndDateTime[0] - $(Get-Date)).Days
write-host “##WILDVALUE##.DaysLeft=$CertExpires"
 

Any insight to this would be helpful! 

  • When you use the BATCH type of script (instead of SCRIPT type) in a DataSource, the wildvalue will not exist because your script will need to output all instances all at once. So for example if you have a DataSource autodiscover that provides 4 instances called A,B,C and D you need your script to output something like this:

    A.DaysLeft=1
    B.DaysLeft=6
    C.DaysLeft=13
    D.DaysLeft=11

    The difference between BATCH and SCRIPT types, is that BATCH needs to provide all the answers at one time as it will be run only once. The SCRIPT type will run once for each instance and LM will pass along that instance in the ##wildvalue## text.

    So your script would need look something like this (pseudocode code):

    Get-AzAdServicePrincipal -All | ForEach-Object {
    $CertExpires = ($_.PasswordCredentials.EndDateTime[0] - $(Get-Date)).Days
    Write-Output “$($_.Name).DaysLeft=$CertExpires"
    }
  • When you use the BATCH type of script (instead of SCRIPT type) in a DataSource, the wildvalue will not exist because your script will need to output all instances all at once. So for example if you have a DataSource autodiscover that provides 4 instances called A,B,C and D you need your script to output something like this:

    A.DaysLeft=1
    B.DaysLeft=6
    C.DaysLeft=13
    D.DaysLeft=11

    The difference between BATCH and SCRIPT types, is that BATCH needs to provide all the answers at one time as it will be run only once. The SCRIPT type will run once for each instance and LM will pass along that instance in the ##wildvalue## text.

    So your script would need look something like this (pseudocode code):

    Get-AzAdServicePrincipal -All | ForEach-Object {
    $CertExpires = ($_.PasswordCredentials.EndDateTime[0] - $(Get-Date)).Days
    Write-Output “$($_.Name).DaysLeft=$CertExpires"
    }
  • Mike you are THE MAN. Thank you for taking the time to explain this! I will adjust accordingly. 

    Cheers!