Private/New-CMHTempSQLfunctions.ps1

function New-CMHTempSQLfunctions {
    param ()
    Write-Log -Message "(New-CMHTempSQLfunctions)" -LogFile $logfile
    $result = @"
CREATE FUNCTION [fn_CM12R2HealthCheck_ScheduleToMinutes](@Input varchar(16))
RETURNS bigint
AS
BEGIN
    if (ISNULL(@Input, '') <> '')
    begin
        declare @hex varchar(64), @flag char(3), @minute char(6), @hour char(5), @day char(5), @Cnt tinyint, @Len tinyint, @Output bigint, @Output2 bigint = 0
         
        set @hex = @Input
 
        SET @HEX=REPLACE (@HEX,'0','0000')
        set @hex=replace (@hex,'1','0001')
        set @hex=replace (@hex,'2','0010')
        set @hex=replace (@hex,'3','0011')
        set @hex=replace (@hex,'4','0100')
        set @hex=replace (@hex,'5','0101')
        set @hex=replace (@hex,'6','0110')
        set @hex=replace (@hex,'7','0111')
        set @hex=replace (@hex,'8','1000')
        set @hex=replace (@hex,'9','1001')
        set @hex=replace (@hex,'A','1010')
        set @hex=replace (@hex,'B','1011')
        set @hex=replace (@hex,'C','1100')
        set @hex=replace (@hex,'D','1101')
        set @hex=replace (@hex,'E','1110')
        set @hex=replace (@hex,'F','1111')
         
        select @Flag = SUBSTRING(@hex,43,3), @minute = SUBSTRING(@hex,46,6), @hour = SUBSTRING(@hex,52,5), @day = SUBSTRING(@hex,57,5)
 
        if (@flag = '010') --SCHED_TOKEN_RECUR_INTERVAL
        BEGIN
            set @Cnt = 1
            set @Len = LEN(@minute)
            set @Output = CAST(SUBSTRING(@minute, @Len, 1) AS bigint)
             
            WHILE(@Cnt < @Len) BEGIN
            SET @Output = @Output + POWER(CAST(SUBSTRING(@minute, @Len - @Cnt, 1) * 2 AS bigint), @Cnt)
            SET @Cnt = @Cnt + 1
            END
            set @Output2 = @Output
             
            set @Cnt = 1
            set @Len = LEN(@hour)
            set @Output = CAST(SUBSTRING(@hour, @Len, 1) AS bigint)
             
            WHILE(@Cnt < @Len) BEGIN
            SET @Output = @Output + POWER(CAST(SUBSTRING(@hour, @Len - @Cnt, 1) * 2 AS bigint), @Cnt)
            SET @Cnt = @Cnt + 1
            END
            set @Output2 = @Output2 + (@Output*60)
             
            set @Cnt = 1
            set @Len = LEN(@day)
            set @Output = CAST(SUBSTRING(@day, @Len, 1) AS bigint)
             
            WHILE(@Cnt < @Len) BEGIN
            SET @Output = @Output + POWER(CAST(SUBSTRING(@day, @Len - @Cnt, 1) * 2 AS bigint), @Cnt)
            SET @Cnt = @Cnt + 1
            END
            set @Output2 = @Output2 + (@Output*60*24)
        END
        ELSE
            set @Output2 = -1
    end
    else
        set @Output2 = -2
         
    return @Output2
END
"@

    Write-Output $result
}