{"id":4662,"date":"2014-03-28T16:14:07","date_gmt":"2014-03-28T07:14:07","guid":{"rendered":"http:\/\/umezawa.dyndns.info\/wordpress\/?p=4662"},"modified":"2014-04-11T13:01:03","modified_gmt":"2014-04-11T04:01:03","slug":"windows-%e3%81%a7%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%a0%e7%9a%84%e3%81%ab%e3%83%a6%e3%83%bc%e3%82%b6%e3%82%92%e8%bf%bd%e5%8a%a0%e5%89%8a%e9%99%a4%ef%bc%88%e5%a4%89%e6%9b%b4%ef%bc%89%e3%81%99","status":"publish","type":"post","link":"http:\/\/umezawa.dyndns.info\/wordpress\/?p=4662","title":{"rendered":"Windows \u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u7684\u306b\u30e6\u30fc\u30b6\u3092\u8ffd\u52a0\/\u524a\u9664\uff08\/\u5909\u66f4\uff09\u3059\u308b (.NET\/C#)"},"content":{"rendered":"<p>ActiveDirectory \u3067\u3082\u30ed\u30fc\u30ab\u30eb\u30a2\u30ab\u30a6\u30f3\u30c8\u3067\u3082\u304a\u304a\u3080\u306d\u540c\u69d8\u306b\u8a18\u8ff0\u3067\u304d\u308b\u3002<\/p>\n<p><!--more--><\/p>\n<blockquote>\n<pre>using System;\r\nusing System.DirectoryServices;\r\nusing System.DirectoryServices.ActiveDirectory;\r\nusing System.DirectoryServices.AccountManagement;\r\n\r\nnamespace AddDelUser\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            string mode = args[0];\r\n            string name = args[1];\r\n\r\n            Domain domain = Domain.GetCurrentDomain();\r\n            PrincipalContext context = new PrincipalContext(ContextType.Domain);\r\n\r\n            if (mode.Equals(\"add\"))\r\n            {\r\n                UserPrincipal principal = new UserPrincipal(context);\r\n                principal.Name = name;\r\n                principal.UserPrincipalName = name + \"@\" + domain.Name;\r\n                principal.SamAccountName = name;\r\n                principal.Enabled = true;\r\n                principal.SetPassword(\"hogehoge1*\");\r\n                principal.PasswordNeverExpires = true;\r\n                principal.Save();\r\n            }\r\n            else\r\n            {\r\n                UserPrincipal principal = UserPrincipal.FindByIdentity(context, IdentityType.Name, name);\r\n                principal.Delete();\r\n            }\r\n        }\r\n    }\r\n}<\/pre>\n<\/blockquote>\n<p><code>UserPrincipalName<\/code> \u306f\u30e6\u30fc\u30b6\u30fc\u30d7\u30ea\u30f3\u30b7\u30d1\u30eb\u540d\uff08umezawa@umead.local \u5f62\u5f0f\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u540d\uff09\u3001<code>SamAccountName<\/code> \u306fSAM\u30a2\u30ab\u30a6\u30f3\u30c8\u540d\uff08NT\u5f62\u5f0f\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u540d\uff09\u3001<code>Name<\/code> \u306f\u300cActive Directory \u30e6\u30fc\u30b6\u30fc\u3068\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u300d\u3067\u300c\u540d\u524d\u300d\u30ab\u30e9\u30e0\u306b\u51fa\u3066\u304f\u308b\u540d\u524d\u3067\u3042\u308b\u30023\u3064\u3068\u3082\u7570\u306a\u308b\u540d\u524d\u3092\u4ed8\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u308b\uff08\u666e\u901a\u306f\u305d\u3093\u306a\u3053\u3068\u3057\u306a\u3044\u3068\u601d\u3046\u304c\uff09\u3002GUI \u64cd\u4f5c\u3067\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u5834\u5408\u306f\u30e6\u30fc\u30b6\u30fc\u30d7\u30ea\u30f3\u30b7\u30d1\u30eb\u540d\u3092\u7a7a\u306b\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u304c\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u7684\u306b\u8ffd\u52a0\u3059\u308b\u5834\u5408\u306f\u30e6\u30fc\u30b6\u30fc\u30d7\u30ea\u30f3\u30b7\u30d1\u30eb\u540d\u306f\u7a7a\u306b\u3067\u304d\u308b\u3057\u3001@ \u4ee5\u964d\u3092\u6301\u305f\u306a\u3044\u540d\u524d\u3082\u4ed8\u3051\u3089\u308c\u308b\u3002SAM\u30a2\u30ab\u30a6\u30f3\u30c8\u540d\u306f\u7a7a\u306b\u306f\u3067\u304d\u305a\u3001\u5024\u3092\u8a2d\u5b9a\u3057\u306a\u3044\u3068\u30e9\u30f3\u30c0\u30e0\u306a\u5024\u304c\u4f7f\u308f\u308c\u3001<code>null<\/code> \u3084\u7a7a\u6587\u5b57\u5217\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u3002<\/p>\n<p>\u3053\u308c\u3060\u3068\u73fe\u5728\u306e\u30c9\u30e1\u30a4\u30f3\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u5834\u6240\uff08\u300cActive Directory \u30e6\u30fc\u30b6\u30fc\u3068\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u300d\u3067\u306e\u30c9\u30e1\u30a4\u30f3\u306e\u4e0b\u306e &#8220;Users&#8221; \u30d5\u30a9\u30eb\u30c0\uff09\u306b\u4f5c\u3089\u308c\u308b\u3002\u4ed6\u306e\u30c9\u30e1\u30a4\u30f3\u306b\u4f5c\u308a\u305f\u3044\u5834\u5408\u306f <code>new PrincipalContext(ContextType.Domain, \"umesub.umead.local\");<\/code> \u306a\u3069\u3068\u3059\u308b\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u4ee5\u5916\u306e\u5834\u6240(DN)\u306b\u4f5c\u308a\u305f\u3044\u5834\u5408\u306f <code>new PrincipalContext(ContextType.Domain, \"umead.local\", \"OU=OtherGroup,DC=umead,DC=local\");<\/code> \u306a\u3069\u3068\u3059\u308b\u3002<\/p>\n<p>\u30ed\u30fc\u30ab\u30eb\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u64cd\u4f5c\u3057\u305f\u3044\u5834\u5408\u306f <code>ContextType.Machine<\/code> \u3092\u4f7f\u3046\u3002\u3053\u306e\u5834\u5408\u3001<code>UserPrincipal<\/code> \u30af\u30e9\u30b9\u306e\u3044\u304f\u3064\u304b\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u4f7f\u3048\u306a\u3044\uff08<code>UserPrincipalName<\/code> \u3068\u304b\uff09\u3002\u30c9\u30e1\u30a4\u30f3\u306e\u5834\u5408\u3068\u540c\u69d8\u306b\u4ed6\u306e\u30de\u30b7\u30f3\u306e\u30ed\u30fc\u30ab\u30eb\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u64cd\u4f5c\u3067\u304d\u308b\u3068\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u306f\u66f8\u3044\u3066\u3042\u308b\u304c\u3001\u8a66\u3057\u3066\u306a\u3044\u3002\u306a\u304a\u3001\u30c9\u30e1\u30a4\u30f3\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u4e0a\u3067 <code>ContextType.Machine<\/code> \u3092\u4f7f\u3063\u3066\u3082\u30a8\u30e9\u30fc\u306b\u306f\u306a\u3089\u305a\u30c9\u30e1\u30a4\u30f3\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u64cd\u4f5c\u3059\u308b\u3053\u3068\u306b\u306a\u308b\u304c\u3001\u3084\u3063\u3071\u308a <code>UserPrincipalName<\/code> \u3068\u304b\u306f\u4f7f\u3048\u306a\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ActiveDirectory \u3067\u3082\u30ed\u30fc\u30ab\u30eb\u30a2\u30ab\u30a6\u30f3\u30c8\u3067\u3082\u304a\u304a\u3080\u306d\u540c\u69d8\u306b\u8a18\u8ff0\u3067\u304d\u308b\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-4662","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4662","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4662"}],"version-history":[{"count":7,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4662\/revisions"}],"predecessor-version":[{"id":4709,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4662\/revisions\/4709"}],"wp:attachment":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4662"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}