SHARE
TWEET

GPOBackup Get-GPDelegation.ps1

Freakling Mar 7th, 2012 200 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $ErrorActionPreference = "Continue"
  2. import-module grouppolicy
  3.  
  4. $Config = [xml](Get-Content Config.xml)
  5. $GPOList = @($Config.Configuration.GPOBackup.GPO.name)
  6. $BackupPath = $Config.Configuration.GPOBackup.path
  7.  
  8. $xmlroot = "<Accountlist></Accountlist>"
  9.  
  10. ForEach($GPONAMES in $GPOList){
  11.   $ALLGPO = get-gpo -all | where {$_.Displayname -like $GPOList}
  12.  
  13.   ForEach ($GPO in $ALLGPO) {
  14.     $GPOname = $GPO.displayname
  15.    
  16.     $GPPermissions = get-gppermissions -Name $GPOname -ALL
  17.    
  18.     $xmltemplate = .\media\cmdlets\Set-TemplateXML.ps1 -Delegation
  19.     $xmlroot | out-file $BackupPath\$GPOname\GPPermissions.xml
  20.    
  21.     ForEach($delegation in $GPPermissions){
  22.       [string]$GPTrustee = $delegation.Trustee.name
  23.       [string]$GPTrusteeType = $delegation.Trustee.SidType
  24.       [string]$GPPermission = $delegation.Permission
  25.       [string]$GPInherited = $delegation.Inherited
  26.      
  27.       $DelegationXML = [xml](Get-Content $BackupPath\$GPOname\GPPermissions.xml)
  28.      
  29.       $NewAccount = $DelegationXML.CreateElement("Account")
  30.       $NewAccount.set_InnerXML("<Trustee>$GPTrustee</Trustee><TrusteeType>$GPTrusteeType</TrusteeType><Permission>$GPPermission</Permission><Inherited>$GPInherited</Inherited>")
  31.      
  32.       $DelegationXML.SelectSingleNode("//Accountlist").AppendChild($NewAccount)
  33.      
  34.       $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++} }
  35.      
  36.       $DelegationXML.save("$BackupPath\$GPOname\GPPermissions.xml")
  37.       $delegation.Permission.value__
  38.       write-host "------"
  39.     }
  40.   }
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top