Bizarre removal errors when running in intune

Hi,

We have been using PSADT for a good number of years however, we are seeing strange errors recently when deploying via intune:

[Asynchronous] :: Failed to delete folder(s) and file(s) from path [C:\WINDOWS\SystemTemp\(our company name)\BlockExecution]. 
Error Record:
-------------

Message        : Cannot remove item C:\WINDOWS\SystemTemp\(our company name)\BlockExecution\AppDeployToolkitBanner.png: The 
                 process cannot access the file 'AppDeployToolkitBanner.png' because it is being used by another 
                 process. Cannot remove item C:\WINDOWS\SystemTemp\(our company name)\BlockExecution: The directory is not 
                 empty.
                 
InnerException : 

FullyQualifiedErrorId : Cannot remove item 
                        C:\WINDOWS\SystemTemp\(our company name)\BlockExecution\AppDeployToolkitBanner.png: The process 
                        cannot access the file 'AppDeployToolkitBanner.png' because it is being used by another 
                        process. Cannot remove item C:\WINDOWS\SystemTemp\(our company name)\BlockExecution: The directory is 
                        not empty.
                        
ScriptStackTrace      : at Remove-Folder<Process>, 
                        C:\WINDOWS\SystemTemp\(our company name)\BlockExecution\AppDeployToolkitMain.ps1: line 5064
                        at Unblock-AppExecution<Process>, 
                        C:\WINDOWS\SystemTemp\(our company name)\BlockExecution\AppDeployToolkitMain.ps1: line 8826
                        at <ScriptBlock>, C:\WINDOWS\SystemTemp\(our company name)\BlockExecution\AppDeployToolkitMain.ps1: 
                        line 16916

PositionMessage : At C:\WINDOWS\SystemTemp\(our company name)\BlockExecution\AppDeployToolkitMain.ps1:5064 char:21
                  +                     Throw $ErrorRemoveFolder

Sometimes as well the PSADT .ico we use cannot be found either.

retries seem to resolve the issue and it does not happen on all devices. Not sure why we are seeing this.

There is a recent thread on Reddit about a similar issue, I wonder if the same advice might solve the issue for you?:
https://www.reddit.com/r/PSADT/comments/1gfqr71/script_failing_not_completing/

That actually makes sense. Thank you!

1 Like

This seems to occur when a blocked app dialog is actively on screen when Exit-Script is called. I ran into this as well, and so I just created a little function that I add to my AppDeployToolkitExtensions.ps1. I then simply call Close-BlockedAppDialog in my Deploy-Application.ps1 as the last thing in my post-install or post-uninstall section.

function Close-BlockedAppDialog {
    <#
    .SYNOPSIS
        Closes any running instances of the Blocked App Dialog.

    .DESCRIPTION
        The Close-BlockedAppDialog function identifies and stops any running instances 
        of the Blocked App Dialog. It utilizes the Get-WmiObject cmdlet to retrieve 
        all processes and filters them to find any with a command line containing 
        '-ShowBlockedAppDialog'. If such processes are found, it stops them using 
        Stop-Process. It logs actions using Write-Log for each process it stops 
        or if no such processes are found.

    .EXAMPLE
        Close-BlockedAppDialog

        This example demonstrates how to call the Close-BlockedAppDialog function. 
        It checks for any running instances of the Blocked App Dialog and stops them 
        if they are found.
        
    #>

    #Stop any running instances of the Blocked App Dialog first
    $ProcsToStop = Get-WmiObject Win32_Process | Where-Object { $_.CommandLine -like '*-ShowBlockedAppDialog*' }
    If ($ProcsToStop) {
        foreach ($proc in $ProcsToStop) {
            Write-Log -Message "Found a Blocked App Dialog process. Stopping process $($proc.ProcessName) with ID $($proc.ProcessId)." -Severity 2
            Stop-Process -Id $proc.ProcessId -Force -ErrorAction SilentlyContinue
        }
    }
    else {
        Write-Log -Message "No instances of Blocked App Dialog running." -Severity 2
    }
}
3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.