Add-GroupMigrationACL.ps1 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. param(
  2. $out = "runtime\acl.csv",
  3. $base = "\\fserver.annax.local\newroot",
  4. [Switch]
  5. $verbose = $false,
  6. $erroraction = "Continue"
  7. )
  8. # $ErrorActionPreference = "Stop"
  9. $ErrorActionPreference = $erroraction
  10. Get-ChildItem $base -Recurse | % {
  11. $dir = $_
  12. try {
  13. # $dir.FullName | out-host
  14. $acl = Get-Acl $dir.FullName
  15. # $acl | Out-Host
  16. $acl.Access | Where-Object { $_.IsInherited -eq $false } | % {
  17. $axacl = $_.IdentityReference.Value
  18. if ($_.IdentityReference.Value -like "ANNAX\*") {
  19. if ($verbose) {
  20. $axacl | Out-Host
  21. }
  22. $wtacl = $null
  23. $acl.Access | Where-Object { $_.IsInherited -eq $false -and (($_.IdentityReference.Value -replace "WABTEC\\ANG_") -eq ($axacl -replace "ANNAX\\")) } | % {
  24. $wtacl = $_.IdentityReference.Value
  25. }
  26. if ($null -eq $wtacl) {
  27. $dir.FullName | Out-Host
  28. $axacl | Out-Host
  29. [PSCustomObject]@{
  30. dir = $dir.FullName
  31. acl = $axacl
  32. err = ""
  33. } | Export-Csv -Append $out
  34. }
  35. else {
  36. if ($verbose) {
  37. "MATCH" | Out-Host
  38. $wtacl | Out-Host
  39. }
  40. }
  41. }
  42. }
  43. }
  44. catch {
  45. [PSCustomObject]@{
  46. dir = $dir.FullName
  47. acl = ""
  48. err = $PSItem.ToString()
  49. } | Export-Csv -Append $out
  50. }
  51. }