@Jim Smith Thanks for posting in our Q&A.
For this issue, did you want to output the account when the account not match "myorgname.co.uk" in the registry? If yes, please understand that this commend "if ($accounts2 = $accounts -notmatch XXX)" only output "true" or "false", it will not output the account. If you want to output 1 and the account, please try to change the script like the following:
$dir = Get-Item HKCU:\SOFTWARE\Microsoft\Office\16.0\Outlook\AutoDiscover
$accounts = ($dir | Select-Object Property -ExpandProperty Property)
if ($accounts -notmatch "myorgname.co.uk"){
$accounts2 =$accounts
Write-Host $accounts2
Write-output 1
Exit 0
}
Hope it will help.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.