Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .Note that this script requires the use of the NTFSSecurity module
- which can be obtained at https://ntfssecurity.codeplex.com/
- #>
- $computers = Get-ADComputer <#your filter here#>
- $contentArray = New-Object System.Collections.ArrayList
- ForEach($computer in $computers){
- $path = "\\$($computer.Name)\c$\Windows\diagnostics\scheduled\Maintenance\TS_BrokenShortcuts.ps1"
- Set-NTFSOwner -Path $path -Account <#domain\adminaccount#>
- Add-NTFSAccess -Path $path -Account <#domain\adminaccount#> -AccessRights FullControl
- $content = Get-Content -Path $path
- $content | ForEach-Object{$contentArray.Add($_) | Out-Null}
- ForEach($line in $contentArray){
- If ($line -match '\[string\]\$list = ""' -and ($contentArray[$contentArray.IndexOf($line) + 1]) -notmatch '<#'){
- $contentArray.Insert(($contentArray.IndexOf($line) + 1), " <#")
- Break
- }
- }
- ForEach($line in $contentArray){
- If ($line -match 'return \$list' -and ($contentArray[$contentArray.IndexOf($line) - 1] -notmatch '#>')){
- $contentArray.Insert($contentArray.IndexOf($line), " #>")
- Break
- }
- }
- $contentArray | Set-Content -Path $path
- Set-NTFSOwner -Path $path -Account 'NT SERVICE\TrustedInstaller'
- Get-NTFSAccess -Path $path | Where-Object {$_.Account -like "*<adminaccount>"} | Remove-NTFSAccess
- }
Advertisement
Add Comment
Please, Sign In to add comment