|
|
@@ -0,0 +1,48 @@
|
|
|
+param(
|
|
|
+ $Path,
|
|
|
+ $Filter="WABTEC\*",
|
|
|
+ $NewOwner=$env:USERNAME,
|
|
|
+ [switch]
|
|
|
+ $Set=$false,
|
|
|
+ [Int]
|
|
|
+ $Depth=99
|
|
|
+)
|
|
|
+$ErrorActionPreference = "stop"
|
|
|
+$NewOwnerAccount = New-Object System.Security.Principal.Ntaccount($NewOwner);
|
|
|
+
|
|
|
+Get-ChildItem -Recurse -Depth $Depth -Path $path | ForEach-Object {
|
|
|
+ $currentPath = $_.FullName
|
|
|
+ try
|
|
|
+ {
|
|
|
+ $ACL = Get-Acl $currentPath
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ Write-Output ("Error getting permissions of: " + $currentPath)
|
|
|
+ throw $_
|
|
|
+ }
|
|
|
+ $Owner = ($ACL).Owner
|
|
|
+
|
|
|
+ $out = [PSCustomObject]@{
|
|
|
+ Path=$currentPath;
|
|
|
+ Owner=$Owner;
|
|
|
+ NewOwner=$NewOwnerAccount;
|
|
|
+ }
|
|
|
+
|
|
|
+ $ACL.SetOwner($NewOwnerAccount) | Out-Null
|
|
|
+
|
|
|
+ if (-not ($Owner -like $Filter)) {
|
|
|
+ $out
|
|
|
+ if ($Set) {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ $ACL | Set-Acl -Path $currentPath;
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ Write-Output ("Error setting permissions of: " + $currentPath)
|
|
|
+ throw $_
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|