Pregunta

I have several COM+ applications that make use of role based security. During any troubleshooting, manually checking each component to ensure that both the 'Enforce component level access checks' and 'Roles explicity set for selected item(s)' boxes are checked can be a pain.

Half the problem has been addressed with the script below (Enforce component level access checks), but I am struggling to find a way to programatically determine if any roles that are assigned to the component also have their checkbox enabled.

Any help much appreciated!

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{    
          $components = $applications.GetCollection("Components",$application.key)
          $components.Populate()

          foreach ($component in $components){

            $componentName = $component.Name;
                Write-Host $componentName;

            $accesschecks = $component.Value("ComponentAccessChecksEnabled");

            Write-Host "Access Checks Enabled: " -NoNewLine;
            Switch ($accesschecks){
                $true{Write-Host $accesschecks -ForegroundColor Green}
                $false{Write-Host $accesschecks -ForegroundColor red -BackgroundColor white}
            }   

            $roles = $applications.GetCollection("Roles",$application.key) ;
            $roles.Populate();
            $rolename = $roles.Item(0).Name;

            #$roleenabled = !!???!!     

            Write-Host "Role: $rolename Enabled: " -NoNewLine;
            Switch ($roleenabled){
                $true{Write-Host $roleenabled -ForegroundColor Green}
                $false{Write-Host $roleenabled -ForegroundColor red -BackgroundColor white}
            } 
            Write-Host;

             }
    }
    catch{}
  }
Write-Host "-------------------------------------";
}

Example COM+ dialogue showing enabled roles

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top