Reboot Pending Error

I have devised a script to detect if the targeted devices have not rebooted for two days and have a system reboot pending with an additional check, to bypass if the users is logged off and the username is “system”. We saw instances where the script would auto exit if one was pending (60012). We would like it to just install in the background.

$lastbootuptime = (Get-ADTPendingReboot).LastBootUpTime
    $rebootpending = (Get-ADTPendingReboot).IsSystemRebootPending
    
    ## if statement to see if user is logged off/away and system is logged on
    if($rebootpending -eq $true -and (Get-ADTLoggedOnUser).UserName -eq "system"){
    Write-ADTLogEntry "User is logged off. Silent install"} 

    ## tests if device is pending a reboot and not rebooted in the past two days with the user logged on.
    if($rebootpending -eq $true -and $lastbootuptime -lt (Get-Date).AddDays(-2) -and (Get-ADTLoggedOnUser).UserName -isnot "system")
    {
    if ((Show-ADTInstallationPrompt -Message "An install of $($ADTsession.InstallTitle) is about to take place but is unable to proceed because your device has a reboot pending. `nPlease can you save any work and reboot so the install can begin." `
    -ButtonRightText 'Reboot Now' -ButtonLeftText 'Reboot Later' -Subtitle "Action Required") -eq 'Reboot Now')
    {
    Restart-Computer -force}
    else
    {
    Close-ADTSession -ExitCode 60012}
    }

for some reason if the device is pending a reboot i get the below error:

Message               : Cannot convert the "system" value of type "System.String" to type "System.Type".
InnerException        : System.Management.Automation.PSInvalidCastException: Cannot convert the "system" value of type "System.String" to type "System.Type".
at System.Management.Automation.LanguagePrimitives.ConvertStringToType(Object valueToConvert, Type resultType, Boolean recursion, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
at System.Management.Automation.LanguagePrimitives.ConversionData`1.Invoke(Object valueToConvert, Type resultType, Boolean recurse, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
at System.Management.Automation.LanguagePrimitives.ConvertTo(Object valueToConvert, Type resultType, Boolean recursion, IFormatProvider formatProvider, TypeTable backupTypeTable)
at System.Management.Automation.ParserOps.ConvertTo[T](Object obj, IScriptExtent errorPosition)

if the user reboots, we dont get this error at all. not sure where i am going wrong.

solved it… needs to be -notlike