Advertisement
Guest User

Untitled

a guest
Jan 30th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. <#
  2.  
  3. SVN Access Level Enum Values
  4. ----------------------------
  5. No Access = 0
  6. Read Only = 1
  7. Read Write = 2
  8.  
  9. #>
  10.  
  11.  
  12. $userAccountObj = @"
  13. public class UserAccount {
  14. public string SID;
  15. public int Access;
  16.  
  17. public UserAccount(string SID, int Access) {
  18. this.SID = SID;
  19. this.Access = Access;
  20. }
  21. }
  22. "@
  23. Add-Type -TypeDefinition $userAccountObj -Language CSharp
  24.  
  25.  
  26. function GetPermObject {
  27. param([string]$sid, [int]$access)
  28.  
  29. ## Import System.Management assembly and create WMI objects
  30. Add-Type -Path $($env:systemroot\Microsoft.NET\Framework64\v2.0.50727\System.Management.dll)
  31.  
  32. $connOpts = New-Object System.Management.ConnectionOptions
  33.  
  34. $connOpts.Impersonation = [System.Management.ImpersonationLevel]::Impersonate;
  35. $connOpts.EnablePrivileges = $true;
  36. if ((-not $snv_host -like "localhost") -or (-not $svn_host -like "127.0.0.1")) {
  37. $connOpts.Username = $cred.UserName;
  38. $connOpts.SecurePassword = $cred.Password;
  39. }
  40.  
  41. $scope = New-Object System.Management.ManagementScope([string]::Format("\\{0}\{1}", $svn_host, "root\VisualSVN"), $connOpts);
  42. $scope.Connect();
  43.  
  44. $se = New-Object System.Management.ManagementPath -ArgumentList "VisualSVN_PermissionEntry";
  45. $secEntry = New-Object System.Management.ManagementClass($scope, $se, $null);
  46.  
  47. $wa = New-Object System.Management.ManagementPath -ArgumentList "VisualSVN_WindowsAccount";
  48. $account = New-Object System.Management.ManagementClass($scope, $wa, $null);
  49.  
  50. $account.SetPropertyValue("SID", $sid);
  51.  
  52. $secEntry.SetPropertyValue("AccessLevel", $access);
  53. $secEntry.SetPropertyValue("Account", $account);
  54.  
  55. $secEntry
  56. }
  57.  
  58.  
  59. function SetPermissions{
  60. param($repoObj, [string]$path, [object[]]$permissions)
  61.  
  62. Add-Type -Path $($env:systemroot\Microsoft.NET\Framework64\v2.0.50727\System.Management.dll)
  63.  
  64. $permsObj = New-Object System.Collections.ArrayList
  65. $permissions | ForEach-Object -Process { $permsObj.Add($(GetPermObject -sid $_.SID -access $_.Access)) };
  66.  
  67. $inParams = $repoObj.GetMethodParameters("SetSecurity");
  68. $inParams.SetPropertyValue("Path", $path);
  69. $inParams.ResetChildren = $true
  70. $inParams.Permissions = $permsObj.ToArray();
  71.  
  72. $repoObj.InvokeMethod("SetSecurity", $inParams, $null);
  73. }
  74.  
  75.  
  76. ## Set security on repository
  77. Write-Host "Setting security on repository"
  78. $ad_noaccess_group = Get-ADGroup -Filter {Name -like $noaccess_group}
  79. $ad_read_group = Get-ADGroup -Filter {Name -like $read_group}
  80. $ad_write_group = Get-ADGroup -Filter {Name -like $write_group}
  81.  
  82. $svn_groups = @()
  83. $svn_groups += New-Object UserAccount -ArgumentList @($ad_noaccess_group.SID.Value, 0)
  84. $svn_groups += New-Object UserAccount -ArgumentList @($ad_read_group.SID.Value, 1)
  85. $svn_groups += New-Object UserAccount -ArgumentList @($ad_write_group.SID.Value, 2)
  86.  
  87. $repoObj = Get-WmiObject -ComputerName $svn_host -Namespace root\VisualSVN -Class VisualSVN_Repository | ? {$_.Name -like $repo_name}
  88.  
  89. if ($repoObj -ne $null) {
  90. SetPermissions -repoObj $repoObj -path "/" -permissions $svn_groups
  91. } else {
  92. Write-Warning "Cannot find group $repo_name!`nPermissions not set on repository."
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement