During the MVA Windows 8.1 Deployment Jump Start session, I demonstrated a PowerShell that me and Mikael Nystrom put together for an upcoming book. Here it is:
The syntax to run it is: Set-OUPermissions.ps1 -Account CM_JD -TargetOU OU=Workstations,OU=ViaMonstra"
Account is the account in AD for which you want to assign permissions, TargetOU is for which OU.
You don’t need to specify the domain, the script finds your domain.
<# Script name: Configure-OUPermissions Created: 2013-01-08 Version: 1.0 Author Mikael Nystrom and Johan Arwidmark Homepage: http://www.deploymentfundamentals.com Disclaimer: This script is provided "AS IS" with no warranties, confers no rights and is not supported by the authors or DeploymentArtist. Author - Mikael Nystrom Twitter: @mikael_nystrom Blog : http://deploymentbunny.com Author - Johan Arwidmark Twitter: @jarwidmark Blog : http://deploymentresearch.com #> Param ( [parameter(mandatory=$true,HelpMessage="Please, provide a name.")][ValidateNotNullOrEmpty()]$Account, [parameter(mandatory=$true,HelpMessage="Please, provide the password to be used.")][ValidateNotNullOrEmpty()]$TargetOU ) # Start logging to screen Write-host (get-date -Format u)" - Starting" # This i what we typed in Write-host "Account to search for is" $Account Write-Host "OU to search for is" $TargetOU $CurrentDomain = Get-ADDomain $OrganizationalUnitDN = $TargetOU+","+$CurrentDomain $SearchAccount = Get-ADUser $Account $SAM = $SearchAccount.SamAccountName $UserAccount = $UserDomain+"\"+$SAM Write-Host "Account is = $UserAccount" Write-host "OU is =" $OrganizationalUnitDN dsacls.exe $OrganizationalUnitDN /G $UserAccount":CCDC;Computer" /I:T | Out-Null dsacls.exe $OrganizationalUnitDN /G $UserAccount":LC;;Computer" /I:S | Out-Null dsacls.exe $OrganizationalUnitDN /G $UserAccount":RC;;Computer" /I:S | Out-Null dsacls.exe $OrganizationalUnitDN /G $UserAccount":WD;;Computer" /I:S | Out-Null dsacls.exe $OrganizationalUnitDN /G $UserAccount":WP;;Computer" /I:S | Out-Null dsacls.exe $OrganizationalUnitDN /G $UserAccount":RP;;Computer" /I:S | Out-Null dsacls.exe $OrganizationalUnitDN /G $UserAccount":CA;Reset Password;Computer" /I:S | Out-Null dsacls.exe $OrganizationalUnitDN /G $UserAccount":CA;Change Password;Computer" /I:S | Out-Null dsacls.exe $OrganizationalUnitDN /G $UserAccount":WS;Validated write to service principal name;Computer" /I:S | Out-Null dsacls.exe $OrganizationalUnitDN /G $UserAccount":WS;Validated write to DNS host name;Computer" /I:S | Out-Null dsacls.exe $OrganizationalUnitDN/ Johan
More ...