asked on
$URL = “LDAP://DC= MYDOMAIN,DC=local”;
$root = New-Object DirectoryServices.DirectoryEntry $URL
$ds = New-Object DirectoryServices.DirectorySearcher
$ds.SearchRoot = $root
$ds.filter = “objectCategory=Person”
$src = $ds.FindAll()
Write-Host $src.Count ” user objects found.`n”
$src | %{
$de = $_.GetDirectoryEntry()
$accessrules = $de.get_ObjectSecurity().GetAccessRules($true, $false,[System.Security.Principal.SecurityIdentifier]) | ?{$_.IdentityReference -eq “S-1-5-32-561¿}
if ((Measure-Object -inputobject $accessrules).Count -eq 0)
{
$ar = New-Object System.DirectoryServices.ActiveDirectoryAccessRule([System.Security.Principal.SecurityIdentifier]“S-1-5-32-561¿, “ReadProperty, WriteProperty”, “Allow”, [guid]“5805bc62-bdc9-4428-a5e2-856a0f4c185e”)
$de.get_ObjectSecurity().AddAccessRule($ar)
$de.CommitChanges()
Write-Host -f yellow (“Added:`t” + $de.properties["sAMAccountName"])
Start-Sleep -m 200
}
else
{
Write-Host -f green (“Unchanged:`t” + $de.properties["sAMAccountName"])
}
}
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host
Write-Host "A"
Write-Host "B"
Write-Host "C"
Unexpected token 'S-1-5-32-561?' in expression or statement.
At C:\userattributes.ps1:13 char:129
+ $ar = New-Object System.DirectoryServices.ActiveDirec toryAccess Rule([Syst em.S
ecurity.Principal.SecurityIdentifier ]"S-1-5-32 -561? <<<< , "ReadProperty, Write
Property", "Allow", [guid]"5805bc62-bdc9-4428-a5e2-856a0 f4c185e")
+ CategoryInfo : ParserError: (S-1-5-32-561?:String) [], ParentCo
ntainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
Active Directory (AD) is a Microsoft brand for identity-related capabilities. In the on-premises world, Windows Server AD provides a set of identity capabilities and services, and is hugely popular (88% of Fortune 1000 and 95% of enterprises use AD). This topic includes all things Active Directory including DNS, Group Policy, DFS, troubleshooting, ADFS, and all other topics under the Microsoft AD and identity umbrella.
TRUSTED BY
Open in new window
is so much better to read ...