Issues Running Compliance Search in PowerShell

Running a new compliance search seems to be having issues. The script does not produce errors while using the app registration we created in Azure but the Content Search in Purview doesn’t show any results.
When using user credentials we do not experience this issue so I suspect a permissions issue but I can’t seem to find where.
Any assistance would be greatly appreciated.

Full script below.

`# Get Primary Domain Controller (PDC) Server
$pdc = (Get-ADForest | Select-Object -ExpandProperty RootDomain | Get-ADDomain | Select-Object -Property PDCEmulator).PDCEmulator
# Set Destination Varibales for Output Files
$Root_Disk = "Z:"
$PSTArchive = "$($Root_Disk)PSTArchive"
$SharePath = ""
if (!(Test-Path $PSTArchive)) { New-Item $PSTArchive -ItemType Directory }
$Time = (Get-Date).ToString("yyyyMMddhhmm")
#################################################################################################
# Setup Output Logging
#################################################################################################
# Gets the current date and formats it to Year Month Day Hour Minute format as a time stamp
$time = (Get-Date).ToString("yyyyMMddhhmm")
[string]$script_name = $myInvocation.MyCommand
[string]$script_name
# Checks if path exist if not creates the directory
if (!(Test-Path "C:scriptslog")) { New-Item "C:scriptslog" -ItemType Directory }
#specify Log path
$log_directory = "C:scriptslog$(($script_name).Substring(0,(($script_name).length-4)))"
# Creates directory if it doesn't exists
if (!(Test-Path $log_directory)) { New-Item -Path $log_directory -ItemType Directory }  
# This sets the default path to C:scriptslogsscript_name-datetime.log
Write-Host "Default Log file is $($log_directory)-$($time).log"
$log_path = "$($log_directory)-$($time).log"
# Logs all output to log path
Start-Transcript $log_path
Write-Host "

"
Write-Host ([Environment]::UserDomainName + "" + [Environment]::UserName) " Executed the script at $(Get-Date)`n`n"
#################################################################################################
#################################################################################################
# Set OU path to target employees
$Terminated_Users_OU = ""
# Get terminanted users from AD with extensionAttribute4 set to null
$TerminatedUsers = Get-ADUser -properties extensionAttribute4, enabled -Filter { enabled -eq $false -and -not(extensionAttribute4 -like "*") } -SearchBase $Terminated_Users_OU | Select-Object -First 5
# Connect to Exchange Online
Import-Module ExchangeOnlineManagement
$tenant_name = ""
$app_id = ""
$certificate_thumbprint = ""
Write-Host "Connecting to Exchange Online`n`n" 
Connect-ExchangeOnline -CertificateThumbprint $certificate_thumbprint -AppId $app_id -Organization $tenant_name
Write-Host "Connect to Exhcnage Security `n`n"
Connect-IPPSSession -AppId $app_id -CertificateThumbprint $certificate_thumbprint -Organization $tenant_name
$connection_id = (Get-ConnectionInformation).ConnectionId
# Loop through each terminated user
foreach ($user in $TerminatedUsers) 
{
    # Use Try catch to check for emails
    try
    {
        Get-EXOMailbox -Identity $user.UserPrincipalName -ErrorAction Stop
        # Create PST file name with users UPN
        $Formatted_User_Name = ($user.UserPrincipalName).Substring(0, ($user.UserPrincipalName).indexof("@") - 1)
        # $PSTFileName = "$($user.UserPrincipalName.Replace("@","_"))_Archive.pst"
        $PSTFileName = "$($Formatted_User_Name)_$($Time)_Archive.pst"
        $PSTFilePath = Join-Path -Path $PSTArchive -ChildPath $PSTFileName
        # Start Client Search 
        # Export mailbox to PST file
        try
        {
            Write-Host "Exporting Mailbox to pst for $($user.UserPrincipalName) `n`n"
            #New-MailboxExportRequst -Mailbox $user.UserPrincipalName -FilePath $PSTFilePath -ErrorAction Stop
            
            New-ComplianceSearch "$($user.SamAccountName)_archive_box" -exchangelocation $user.UserPrincipalName | Start-ComplianceSearch 
            Get-ADUser $user.SamAccountName | Set-ADObject -Server $pdc -Replace @{extensionAttribute4 = "Exported" }
        }
        catch
        {
            # Do not flag the user as Exported since the job didn't complete
            Write-Host "Exception happened `n`n"
        }
    }
    catch
    {
        # Flag the user for NoMailBox since it can't be found in exchange online
        Write-Host "User: $($user.UserPrincipalName) has no mailbox"
        Get-ADUser $user.SamAccountName | Set-ADObject -Server $pdc -Replace @{extensionAttribute4 = "NoMailBox" }
    }
}
# Move PST files to designated path
$PSTs = Get-ChildItem -Path $PSTArchive -File
Write-Host "Moving $($PSTs.count) PST Files`n"
foreach ($PST in $PSTs.FullName)
{
    Write-Host "Moving $($PST.FullName) to $($SharePath)`n`n"
    Move-Item -Path $PST -Destination $SharePath -Force
}
# Disconnect from Exchange Online
Write-Host "Disconnecting Session From Exchange Online`n"
Disconnect-ExchangeOnline -ConnectionId $connection_id -Confirm:$false
Stop-Transcript`

New contributor

cmeader1053 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật