Created
March 25, 2014 19:19
-
-
Save jeffpatton1971/9769168 to your computer and use it in GitHub Desktop.
Copy security between Ou's
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Template script | |
.DESCRIPTION | |
This script sets up the basic framework that I use for all my scripts. | |
.PARAMETER | |
.EXAMPLE | |
.NOTES | |
ScriptName : Copy-Delegations.ps1 | |
Created By : jspatton | |
Date Coded : 03/25/2014 12:45:57 | |
ScriptName is used to register events for this script | |
ErrorCodes | |
100 = Success | |
101 = Error | |
102 = Warning | |
104 = Information | |
.LINK | |
https://code.google.com/p/mod-posh/wiki/Production/Copy-Delegations.ps1 | |
#> | |
[CmdletBinding()] | |
Param | |
( | |
[string]$SourceDN, | |
[string]$DestDN, | |
[pscredential]$Credential | |
) | |
Begin | |
{ | |
[string]$ScriptName = $MyInvocation.MyCommand.ToString() | |
[string]$ScriptPath = $MyInvocation.MyCommand.Path | |
[string]$Username = $env:USERDOMAIN + "\" + $env:USERNAME | |
New-EventLog -Source $ScriptName -LogName 'Windows Powershell' -ErrorAction SilentlyContinue | |
[string]$Message = "Script: " + $ScriptPath + "`nScript User: " + $Username + "`nStarted: " + (Get-Date).toString() | |
Write-EventLog -LogName 'Windows Powershell' -Source $ScriptName -EventID "104" -EntryType "Information" -Message $Message | |
# Dotsource in the functions you need. | |
[int]$ADS_OPTION_SECURITY_MASK = 3 | |
[string]$ADS_SECURITY_INFO_DACL = '&H4' | |
} | |
Process | |
{ | |
[System.DirectoryServices.DirectoryEntry]$SourceDirectoryEntry = New-Object System.DirectoryServices.DirectoryEntry($SourceDN, $Credential.UserName, $Credential.GetNetworkCredential().Password) | |
[System.Security.AccessControl.DirectoryObjectSecurity]$SourceSecurityDescriptor = $SourceDirectoryEntry.ObjectSecurity | |
[System.DirectoryServices.DirectoryEntry]$DestDirectoryEntry = New-Object System.DirectoryServices.DirectoryEntry($DestDN, $Credential.UserName, $Credential.GetNetworkCredential().Password) | |
[string]$SourceSDDL = $SourceSecurityDescriptor.Sddl | |
$DestDirectoryEntry.ObjectSecurity.SetSecurityDescriptorSddlForm($SourceSDDL) | |
$DestDirectoryEntry.CommitChanges() | |
} | |
End | |
{ | |
[string]$Message = "Script: " + $ScriptPath + "`nScript User: " + $Username + "`nFinished: " + (Get-Date).toString() | |
Write-EventLog -LogName 'Windows Powershell' -Source $ScriptName -EventID "104" -EntryType "Information" -Message $Message | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment