{"id":105,"date":"2017-06-27T16:09:06","date_gmt":"2017-06-27T16:09:06","guid":{"rendered":"http:\/\/www.polysyncronism.com\/wordpress\/?p=105"},"modified":"2017-07-03T08:30:54","modified_gmt":"2017-07-03T14:30:54","slug":"active-directory-and-ssis","status":"publish","type":"post","link":"http:\/\/www.polysyncronism.com\/wordpress\/2017\/06\/27\/active-directory-and-ssis\/","title":{"rendered":"Active Directory and SSIS"},"content":{"rendered":"<p>I was looking into ways to get the owner of an Active Directory user. I looked at VBScript and C#.NET. While searching for code and while looking at the objects available in .NET using the object browser I found this MSDN blog entry by <a href=\"https:\/\/social.msdn.microsoft.com\/profile\/Alex+Tcherniakhovski\" target=\"_blank\" rel=\"noopener noreferrer\">Alex Tcherniakhovski<\/a>.<\/p>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/alextch\/2012\/01\/04\/extracting-object-ownership-information-from-active-directory-into-sql\/\">Extracting object ownership information from Active Directory into SQL<\/a><\/p>\n<p>One fact mentioned near the bottom of the blog entry is yet another testimony to keep the Domain Admins group small.<\/p>\n<blockquote><p>Yet another reason to keep Domain Admins group small.<\/p><\/blockquote>\n<p><strong>VBScript<\/strong><\/p>\n<pre class=\"lang:vb decode:true \" title=\"VBScript - Get Active Directory Owner\">Option Explicit\r\n\r\nDim sADDN,objUser,objNtSecurityDescriptor\r\n\r\nsADDN = \"LDAP:\/\/YourContextHere\"\r\n\r\nSet objUser = GetObject (sADDN)\r\n \r\nSet objNtSecurityDescriptor = objUser.Get(\"ntSecurityDescriptor\")\r\nWScript.Echo \"Current owner of this item: \" &amp; objNtSecurityDescriptor.Owner<\/pre>\n<p><strong>C#.NET<\/strong><\/p>\n<p>References Used<br \/>\n<code>Name: System.DirectoryServices<br \/>\nPath: C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5.1\\System.DirectoryServices.dll<br \/>\nVersion: 4.0.0.0<br \/>\nName: System.DirectoryServices.AccountManagement<br \/>\nPath: C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5.1\\System.DirectoryServices.AccountManagement.dll<br \/>\nVersion: 4.0.0.0<br \/>\nName: Active DS Type Library<br \/>\nPath: C:\\Windows\\System32\\activeds.tlb<br \/>\nVersion: 1.0<br \/>\nFile Version: 6.1.7600.16385(win7_rtm.090713-1255)<br \/>\n<\/code><\/p>\n<pre class=\"lang:c# decode:true \" title=\"C#.NET\">using System;\r\nusing System.Security.Principal;\r\nusing System.DirectoryServices;\r\nusing System.DirectoryServices.ActiveDirectory;\r\nusing System.DirectoryServices.AccountManagement;\r\nusing ActiveDs;\r\n\r\nnamespace ADOwner\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n\r\n            string ADDomain = \"yourdomain.com\";\r\n            string ADUser = \"youraduser\";\r\n            string ADPass = \"youradpass\";\r\n            string ADsAMAccountName = \"YOURDOMAIN\\\\USERNAMEHERE\";\r\n\r\n            using (var pc = new PrincipalContext(ContextType.Domain, ADDomain, ADUser, ADPass))\r\n            {\r\n\r\n                \/\/ get UserPrincipal Object\r\n                UserPrincipal inetPerson = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, ADsAMAccountName);\r\n\r\n                \/\/ Get Directory Entry Object\r\n                DirectoryEntry de = inetPerson.GetUnderlyingObject() as DirectoryEntry;\r\n\r\n                \/\/ Get Active Directory Security Object\r\n                ActiveDirectorySecurity ads = de.ObjectSecurity;\r\n\r\n                \/\/ Get sid Object                                                 \r\n                SecurityIdentifier sid = new SecurityIdentifier(ads.GetOwner((typeof(SecurityIdentifier))).Value);\r\n\r\n                \/\/ Translate sid to account\r\n                NTAccount account = (NTAccount)sid.Translate(typeof(NTAccount));\r\n\r\n                \/\/ Get owner string\r\n                Console.WriteLine(\"Owner: {0}\",account.ToString());\r\n                Console.ReadKey();\r\n\r\n            }\r\n\r\n\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>Resources to investigate using Perl<\/p>\n<ul>\n<li><a href=\"http:\/\/www.developer.com\/open\/article.php\/3106601\/Searching-Active-Directory-with-Perl.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Searching Active Directory with Perl<\/a><\/li>\n<li><a href=\"https:\/\/www.perl.com\/pub\/2001\/12\/19\/xmlrpc.html\" target=\"_blank\" rel=\"noopener noreferrer\">Building a Bridge to the Active Directory<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I was looking into ways to get the owner of an Active Directory user. I looked at VBScript and C#.NET. While searching for code and while looking at the objects available in .NET using the object browser I found this MSDN blog entry by Alex Tcherniakhovski. Extracting object ownership information from Active Directory into SQL &hellip; <a href=\"http:\/\/www.polysyncronism.com\/wordpress\/2017\/06\/27\/active-directory-and-ssis\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Active Directory and SSIS&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,4,19,17,5],"tags":[],"class_list":["post-105","post","type-post","status-publish","format-standard","hentry","category-c-net","category-code","category-perl","category-research","category-vbscript"],"_links":{"self":[{"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/posts\/105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/comments?post=105"}],"version-history":[{"count":10,"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/posts\/105\/revisions"}],"predecessor-version":[{"id":124,"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/posts\/105\/revisions\/124"}],"wp:attachment":[{"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/media?parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/categories?post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/tags?post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}