Powershell script to manage V1 dbadeposit issues in pull config

Credits:
Superuser
Microsoft Docs

V1 dbadeposit can exit and stop working when in a pull configuration (Normally V1 dbadeposit is setup in a push to configuration) if a tag file (Metadata) is not produced along with the arq file and binary blob file. If you check and find you are actually missing no scans like ourselves then feel free to use. If you find you are missing scans DO NOT USE, fix the problem first. Errored entries which produce an .err file are kept as they are genuine errors that don’t cause the software to fall over, file so I always look for the tag file. The batch can actually be changed from deleting files to moving files, however for us the arq file simply contains [PCL]

rem change drive to required drive letter
d:
cd 
$Afiles = ls *.arq
$Bfiles = ls *.tag
$Alist = @()
$Blist = @()

foreach( $A in $Afiles)
{
    $Alist += $A.BaseName
}
foreach( $B in $Bfiles)
{
    $Blist += $B.BaseName
}
foreach($A in $Alist)
{
    if($Blist -notcontains $a)
    {
        rm ("$A.arq")
    }
}