Cracked it. If the role box is not checked within the Component security settings then the role is not listed in the RolesforComponent collection, as if there is no role at all. Also there may be multiple roles assigned to a component so needed another loop to enumerate:
Clear-Host;
$comAdmin = New-Object -com ("COMAdmin.COMAdminCatalog.1");
$applications = $comAdmin.GetCollection("Applications") ;
$applications.Populate() ;
$appfilter = "ABC";
foreach ($application in $applications){
if($application.name.substring(0,3) -eq $appfilter){
try{
Write-Host $application.name -ForegroundColor White;
$components = $applications.GetCollection("Components",$application.key)
$components.Populate()
foreach ($component in $components){
$componentName = $component.Name;
$componentID = $component.Value("CLSID");
Write-Host "*"$componentName;
$accesschecks = $component.Value("ComponentAccessChecksEnabled");
Write-Host " Access Checks Enabled: " -NoNewLine;
Switch ($accesschecks){
$true{Write-Host $accesschecks -ForegroundColor Blue -BackgroundColor Green}
$false{Write-Host $accesschecks -ForegroundColor White -BackgroundColor Red}
}
}
$RolesForComponent = $components.GetCollection("RolesForComponent",$component.Value("CLSID"))
$RolesForComponent.Populate();
If ($RolesForComponent.Count -eq 0){
Write-Host " " -NoNewLine;
Write-Host "Check Roles!" -ForegroundColor White -BackgroundColor Red;
}
Else{
foreach ($role in $RolesForComponent){
$rolename = $role.Name;
Write-Host " " -NoNewLine;
Write-Host $rolename -NoNewLine;
Write-Host " " -NoNewLine;
Write-Host "Role OK" -ForegroundColor Blue -BackgroundColor Green;
Write-Host;
}
}
}
catch{}
}
Write-Host "----------------------------------------------------------------------";
}
More info here MSDN RolesForComponent collection