How to get the groups of a user in Active Directory? (c#, asp.net)

If you’re on .NET 3.5 or up, you can use the new System.DirectoryServices.AccountManagement (S.DS.AM) namespace which makes this a lot easier than it used to be. Read all about it here: Managing Directory Security Principals in the .NET Framework 3.5 Update: older MSDN magazine articles aren’t online anymore, unfortunately – you’ll need to download the … Read more

Can I get more than 1000 records from a DirectorySearcher?

You need to set DirectorySearcher.PageSize to a non-zero value to get all results. BTW you should also dispose DirectorySearcher when you’re finished with it using(var srch = new DirectorySearcher(dirEnt, “(objectClass=Group)”, loadProps)) { srch.PageSize = 1000; var results = srch.FindAll(); } The API documentation isn’t very clear, but essentially: when you do a paged search, the … Read more

Gradle proxy configuration

Refinement over Daniel’s response: HTTP Only Proxy configuration gradlew -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128 “-Dhttp.nonProxyHosts=*.nonproxyrepos.com|localhost” HTTPS Only Proxy configuration gradlew -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3129 “-Dhttp.nonProxyHosts=*.nonproxyrepos.com|localhost” Both HTTP and HTTPS Proxy configuration gradlew -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3129 “-Dhttp.nonProxyHosts=*.nonproxyrepos.com|localhost” Proxy configuration with user and password gradlew -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128 – Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3129 -Dhttps.proxyUser=user -Dhttps.proxyPassword=pass -Dhttp.proxyUser=user -Dhttp.proxyPassword=pass -Dhttp.nonProxyHosts=host1.com|host2.com worked for me (with gradle.properties in … Read more

Get-Aduser -Filter will not accept a variable

There is valuable information in the existing answers, but I think a more focused summary is helpful. Note that the original form of this answer advocated strict avoidance of script blocks ({…}) and AD-provider variable evaluation, but this has been replaced with more nuanced recommendations. tl;dr Get-ADUser -Filter ‘sAMAccountName -eq $SamAc’ Do not quote the … Read more

Validate a username and password against Active Directory?

If you work on .NET 3.5 or newer, you can use the System.DirectoryServices.AccountManagement namespace and easily verify your credentials: // create a “principal context” – e.g. your domain (could be machine, too) using(PrincipalContext pc = new PrincipalContext(ContextType.Domain, “YOURDOMAIN”)) { // validate the credentials bool isValid = pc.ValidateCredentials(“myuser”, “mypassword”); } It’s simple, it’s reliable, it’s 100% … Read more