Saturday 24 October 2009

Get-CARolesOfCaller.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays the CA roles of the caller 
  4. .DESCRIPTION 
  5.     This script instantiates the CA COM object, gets 
  6.     the allowed roles, and displays them. This script 
  7.     also shows use of Bitwise And operations, typical  
  8.     when using output from API calls.  Based on an earlier
  9.     script by Vadims Podans.
  10. .NOTES 
  11.     File Name  : Get-CARolesofCaller.ps1 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell V2 
  14. .LINK 
  15.     This script posted to: 
  16.         http://pshscripts.blogspot.com/2009/10/get-carolesofcallerps1.html
  17.     MSDN Sample posted at: 
  18.         http://msdn.microsoft.com/en-us/library/aa383243%28VS.85%29.aspx 
  19. .EXAMPLE 
  20.     PSH [C:\foo]: .\Get-CARolesOfCaller.ps1' 
  21.     You have the following rights on this CA: Cookham11\Cookham-CookhamCA 
  22.         CA administrator 
  23.         CA officer 
  24.         CA auditor 
  25.         CA backup 
  26.         Enrollment access 
  27. #> 
  28. # Instantiate the COM object 
  29. $CertAdmin = New-Object -com "CertificateAuthority.Admin.1" 
  30.   
  31. # Now get the roles assigned to me 
  32. $CA = "Cookham11\Cookham-CookhamCA" 
  33. $MyRoles = $CertAdmin.GetMyRoles([string] $CA
  34.  
  35. #Display Granular Rights 
  36. "You have the following rights on this CA: {0}" -f $CA 
  37.  switch ($MyRoles){ 
  38. {$MyRoles -band 1}     {"    CA administrator"
  39. {$MyRoles -band 2}     {"    CA officer"
  40. {$MyRoles -band 4}     {"    CA auditor"
  41. {$MyRoles -band 8}     {"    CA backup"
  42. {$MyRoles -band 256}   {"    CA Read access"
  43. {$MyRoles -band 512}   {"    Enrollment access"
  44. default                {"    No CA Access"

No comments: