Saturday, 2 October 2021

Detect autopilot session

 

Ensuring that some apps only install during autopilot is not easily accomplished, you can use the below powershell script as a requirement rule in Intune for the application.This ensure it'll only proceed when the PC is going through autopilot.

 

$username = "defaultuser0"
$currentuser = (Get-Process -IncludeUserName -Name explorer | Select-Object -ExpandProperty UserName).Split('\')[1]

if ($currentuser -eq $username)
{
    Write-Output 1
    Exit 0
}
else {
    exit 1
}

Friday, 1 October 2021

Code42 proactive remediation - Check for last successful backup

There is no easy way to script a check on code42 being active and working on windows PCs. One way is to use the logs to read if Code42 is backing up recently.

 
#By tausif for FICO

###############
if ((Get-Service Code42Service).Status -eq "Running")
{
    #get code42 logged in user
    if (Test-Path "$env:ALLUSERSPROFILE\CrashPlan\.identity")
    {
        $c42currentuser  = (Get-Content $env:ALLUSERSPROFILE\CrashPlan\.identity) | Select-String -Pattern "username"
        #Get last backup date
        ##################################################################################
        $todaysdate = Get-Date -UFormat "%m/%d/%y"
        $dt = [DateTIme]$todaysdate
        $todayminus60 = $dt.AddDays(-60)
        $logdatepattern = "\d{2}/\d{2}/\d{2}"
        if (Test-Path "$env:ALLUSERSPROFILE\CrashPLan\Log\history.log.0") 
        {
            $lastlinedateonhistorylog = (Get-Content $env:ALLUSERSPROFILE\CrashPLan\Log\history.log.0)[-1] | Select-String -Pattern $logdatepattern | foreach {$_.Matches.Groups[0].Value}

            $patcompletedbackuptoprecloud = "Completed backup to PROe Cloud"
            $backupcompleteline = (Get-Content $env:ALLUSERSPROFILE\CrashPlan\Log\history.log.0 | Select-String -Pattern $patcompletedbackuptoprecloud )[-1]
            $backuppaths = (Get-Content $env:ALLUSERSPROFILE\CrashPLan\Log\app.log)|  Select-String -pattern  "backupPaths  "
            $lastbackupdate = [string]$backupcompleteline | Select-String -Pattern $logdatepattern | foreach {$_.Matches.Groups[0].Value}
            $ndt = [DateTIme]$lastbackupdate
            $dayssincelastbackup = (New-TimeSpan -Start $ndt -End $dt).TotalDays

            ######

            If ($dayssincelastbackup -ge "30")
            {
               
                Write-Output "More than $dayssincelastbackup since last backup, Last back up date: $lastbackupdate, C42 logged on $c42currentuser, $backuppaths"
    
                exit 1
            }
            else
            {
                Write-Output "Days since last backup $dayssincelastbackup, Last back up date: $lastbackupdate, C42 logged on $c42currentuser, $backuppaths"
                exit 0
            }
        }
        else
        {
            Write-Output "No history of successful backup"
            exit 1
        }


    }
    else
    {
        Write-Output "No User logged in"
        exit 1
    }
}
else
{
    Write-Output "Code42 Service not running"
    exit 1
}

Remove Box tools-per user install


Detect autopilot session

  Ensuring that some apps only install during autopilot is not easily accomplished, you can use the below powershell script as a requiremen...