Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ErrorActionPreference = "Continue"
- import-module grouppolicy
- $Config = [xml](Get-Content Config.xml)
- $GPOList = @($Config.Configuration.GPOBackup.GPO.name)
- $BackupPath = $Config.Configuration.GPOBackup.path
- $xmlroot = "<Accountlist></Accountlist>"
- ForEach($GPONAMES in $GPOList){
- $ALLGPO = get-gpo -all | where {$_.Displayname -like $GPOList}
- ForEach ($GPO in $ALLGPO) {
- $GPOname = $GPO.displayname
- $GPPermissions = get-gppermissions -Name $GPOname -ALL
- $xmltemplate = .\media\cmdlets\Set-TemplateXML.ps1 -Delegation
- $xmlroot | out-file $BackupPath\$GPOname\GPPermissions.xml
- ForEach($delegation in $GPPermissions){
- [string]$GPTrustee = $delegation.Trustee.name
- [string]$GPTrusteeType = $delegation.Trustee.SidType
- [string]$GPPermission = $delegation.Permission
- [string]$GPInherited = $delegation.Inherited
- $DelegationXML = [xml](Get-Content $BackupPath\$GPOname\GPPermissions.xml)
- $NewAccount = $DelegationXML.CreateElement("Account")
- $NewAccount.set_InnerXML("<Trustee>$GPTrustee</Trustee><TrusteeType>$GPTrusteeType</TrusteeType><Permission>$GPPermission</Permission><Inherited>$GPInherited</Inherited>")
- $DelegationXML.SelectSingleNode("//Accountlist").AppendChild($NewAccount)
- $silent = $DelegationXML.get_OuterXML().Replace("<", "`t<").Replace(">", ">`t").Replace(">`t`t<", ">`t<").Split("`t") | ForEach-Object {$x=0}{ If ($_.StartsWith("</")) {$x--} ElseIf($_.StartsWith("<")) { $x++}; (" " * ($x)) + $_; if ($_.StartsWith("</")) { $x--} elseif ($_.StartsWith("<")) {$x++} }
- $DelegationXML.save("$BackupPath\$GPOname\GPPermissions.xml")
- $delegation.Permission.value__
- write-host "------"
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement