You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
5.0 KiB

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <Types xmlns="http://schemas.microsoft.com/PowerShell/TypeData/2007/04">
  3. <!--<Types>-->
  4. <Type>
  5. <Name>System.IO.FileInfo</Name>
  6. <Members>
  7. <ScriptProperty>
  8. <Name>Owner</Name>
  9. <GetScriptBlock>
  10. [Security2.IdentityReference2]$this.GetAccessControl().GetOwner([System.Security.Principal.SecurityIdentifier])
  11. </GetScriptBlock>
  12. </ScriptProperty>
  13. <ScriptProperty>
  14. <Name>IsInheritanceBlocked</Name>
  15. <GetScriptBlock>
  16. $this.GetAccessControl([System.Security.AccessControl.AccessControlSections]::Access).AreAccessRulesProtected
  17. </GetScriptBlock>
  18. </ScriptProperty>
  19. <ScriptProperty>
  20. <Name>LengthOnDisk</Name>
  21. <GetScriptBlock>
  22. $driveInfo = New-Object NTFS.DriveInfoExt($this.PSDrive.Name + ":")
  23. [Math]::Ceiling($this.Length / ($driveInfo.BytesPerSector * $driveInfo.SectorsPerCluster)) * ($driveInfo.BytesPerSector * $driveInfo.SectorsPerCluster)
  24. </GetScriptBlock>
  25. </ScriptProperty>
  26. <AliasProperty>
  27. <Name>Size</Name>
  28. <ReferencedMemberName>LengthOnDisk</ReferencedMemberName>
  29. </AliasProperty>
  30. <ScriptMethod>
  31. <Name>EnableInheritance</Name>
  32. <Script>
  33. $sd = $this.GetAccessControl([System.Security.AccessControl.AccessControlSections]::Access)
  34. try
  35. {
  36. $sd.SetAccessRuleProtection($false, $null)
  37. $this.SetAccessControl($sd)
  38. }
  39. catch [Exception]
  40. {
  41. Write-Error -Exception $_.Exception -Message "Error enabling inheritance on item $($this.FullName)"
  42. }
  43. </Script>
  44. </ScriptMethod>
  45. <ScriptMethod>
  46. <Name>DisableInheritance</Name>
  47. <Script>
  48. param(
  49. [Parameter(Position = 0, Mandatory = $false)]
  50. [bool] $CopySecurity = $true
  51. )
  52. $sd = $this.GetAccessControl([System.Security.AccessControl.AccessControlSections]::Access)
  53. try
  54. {
  55. $sd.SetAccessRuleProtection($true, $CopySecurity)
  56. $this.SetAccessControl($sd)
  57. }
  58. catch [Exception]
  59. {
  60. Write-Error -Exception $_.Exception -Message "Error enabling inheritance on item $($this.FullName)"
  61. }
  62. </Script>
  63. </ScriptMethod>
  64. <ScriptMethod>
  65. <Name>GetHash</Name>
  66. <Script>
  67. $hash = [System.Security.Cryptography.SHA1]::Create().ComputeHash($this.OpenRead())
  68. $sb = New-Object System.Text.StringBuilder($hash.Length)
  69. for ($i = 0; $i -lt $hash.Length; $i++)
  70. {
  71. [Void]$sb.Append($hash[$i].ToString("X2"))
  72. }
  73. $sb.ToString()
  74. </Script>
  75. </ScriptMethod>
  76. </Members>
  77. </Type>
  78. <Type>
  79. <Name>System.IO.DirectoryInfo</Name>
  80. <Members>
  81. <ScriptProperty>
  82. <Name>Owner</Name>
  83. <GetScriptBlock>
  84. [Security2.IdentityReference2]$this.GetAccessControl().GetOwner([System.Security.Principal.SecurityIdentifier])
  85. </GetScriptBlock>
  86. </ScriptProperty>
  87. <ScriptProperty>
  88. <Name>IsInheritanceBlocked</Name>
  89. <GetScriptBlock>
  90. $this.GetAccessControl([System.Security.AccessControl.AccessControlSections]::Access).AreAccessRulesProtected
  91. </GetScriptBlock>
  92. </ScriptProperty>
  93. <ScriptMethod>
  94. <Name>EnableInheritance</Name>
  95. <Script>
  96. $sd = $this.GetAccessControl([System.Security.AccessControl.AccessControlSections]::Access)
  97. try
  98. {
  99. $sd.SetAccessRuleProtection($false, $null)
  100. $this.SetAccessControl($sd)
  101. }
  102. catch [Exception]
  103. {
  104. Write-Error -Exception $_.Exception -Message "Error enabling inheritance on item $($this.FullName)"
  105. }
  106. </Script>
  107. </ScriptMethod>
  108. <ScriptMethod>
  109. <Name>DisableInheritance</Name>
  110. <Script>
  111. param(
  112. [Parameter(Position = 0, Mandatory = $false)]
  113. [bool] $CopySecurity = $true
  114. )
  115. $sd = $this.GetAccessControl([System.Security.AccessControl.AccessControlSections]::Access)
  116. try
  117. {
  118. $sd.SetAccessRuleProtection($true, $CopySecurity)
  119. $this.SetAccessControl($sd)
  120. }
  121. catch [Exception]
  122. {
  123. Write-Error -Exception $_.Exception -Message "Error enabling inheritance on item $($this.FullName)"
  124. }
  125. </Script>
  126. </ScriptMethod>
  127. </Members>
  128. </Type>
  129. <Type>
  130. <Name>Security2.FileSystemAccessRule2</Name>
  131. <Members>
  132. <ScriptProperty>
  133. <Name>AccountType</Name>
  134. <GetScriptBlock>
  135. if (-not [System.Security.Principal.WindowsIdentity]::GetCurrent().Name.ToLower().Contains([System.Environment]::MachineName.ToLower()))
  136. {
  137. try
  138. {
  139. ([ADSI]"LDAP://&lt;SID=$($this.Account.Sid)&gt;").ObjectClass[-1]
  140. }
  141. catch
  142. {
  143. [string]::Empty
  144. }
  145. }
  146. </GetScriptBlock>
  147. </ScriptProperty>
  148. </Members>
  149. </Type>
  150. </Types>