{"id":1034,"date":"2013-07-23T17:20:09","date_gmt":"2013-07-23T15:20:09","guid":{"rendered":"http:\/\/michlstechblog.info\/blog\/?p=1034"},"modified":"2013-07-23T17:44:02","modified_gmt":"2013-07-23T15:44:02","slug":"powershell-active-directory-domain-operations","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/powershell-active-directory-domain-operations\/","title":{"rendered":"Powershell: Active Directory Domain Operations"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_1034 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_1034')){$('.twoclick_social_bookmarks_post_1034').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Powershell%3A%20Active%20Directory%20Domain%20Operations\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Asome%20commands%20to%20manage%20Active%20Directory%20Domain%20Controllers%20by%20using%20the%20.NET%20System.DirectoryServices.ActiveDirectory.Domain%20Class.%0D%0ALoad%20the%20assembly%0D%0A%0D%0A%5Bpowershell%5D%0D%0A%5Breflection.assembly%5D%3A%3ALoadWithPartialName%28%26quot%3BSystem.DirectoryServices.Protocols%26quot%3B%29%7COut-Null%0D%0A%0D%0A%5B%2Fpowershell%5D%0D%0A%0D%0AGet%20a%20Domain%20Object%20with%20the%20logon%20Domain%20of%20the%20current%20user%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/powershell-active-directory-domain-operations\\\/\",\"post_id\":1034,\"post_title_referrer_track\":\"Powershell%3A+Active+Directory+Domain+Operations\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>some commands to manage Active Directory Domain Controllers by using the .NET System.DirectoryServices.ActiveDirectory.Domain Class.<br \/>\nLoad the assembly<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n&#x5B;reflection.assembly]::LoadWithPartialName(&quot;System.DirectoryServices.Protocols&quot;)|Out-Null\r\n\r\n<\/pre>\n<p>Get a Domain Object with the logon Domain of the current user<br \/>\n<!--more--><\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$oADDomain=&#x5B;System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()\r\n\r\n<\/pre>\n<p>or get a Domain Object with the Domain of the computer<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$oADDomain=&#x5B;System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()\r\n\r\n<\/pre>\n<p>Get Domainmode and role owners&#8230;<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nwrite-host &quot; Domain mode:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &quot; $oADDomain.DomainMode\r\nwrite-host &quot; PDC Emulator:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &quot; $oADDomain.PdcRoleOwner\r\nwrite-host &quot; Infrastructure master:\u00a0\u00a0 &quot; $oADDomain.InfrastructureRoleOwner\r\nwrite-host &quot; Relative ID (RID) master:&quot; $oADDomain.RidRoleOwner\r\nwrite-host &quot; Parent domain:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &quot; $oADDomain.parent\r\nwrite-host &quot; Subdomains(if there are):&quot; $oADDomain.children\r\n<\/pre>\n<p>Get a list of all Domaincontrollers<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$coDCs=$oADDomain.FindAllDomainControllers()\r\n\r\n<\/pre>\n<p>The following command shows a list of all DC&#8217;s with its Name and IP Address<br \/>\nPossibly other properties are<br \/>\nForest,CurrentTime,HighestCommittedUsn,OSVersion,Roles,Domain,IPAddress,SiteName,Partitions<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$coDCs|Format-Table -Property Name,IPAddress\r\n<\/pre>\n<p>List all trusted domains with trust-type and trustdirection<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$oADDomain.GetAllTrustRelationships()| format-table\r\n\r\n<\/pre>\n<p>Get informations of specific trust<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$oADDomain.GetTrustRelationship(&quot;trusteddomain.com&quot;)\r\n\r\n<\/pre>\n<p>Is the inbound trust relationship of domain a selective one<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$oADDomain.GetSelectiveAuthenticationStatus(&quot;trusteddomain.com&quot;)\r\n\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, some commands to manage Active Directory Domain Controllers by using the .NET System.DirectoryServices.ActiveDirectory.Domain Class. Load the assembly &#x5B;reflection.assembly]::LoadWithPartialName(&quot;System.DirectoryServices.Protocols&quot;)|Out-Null Get a Domain Object with the logon Domain of the current user<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[95,256,255,133,257,20],"class_list":["post-1034","post","type-post","status-publish","format-standard","hentry","category-windowsscripts","tag-active-directory","tag-domainmode","tag-get-domaincontrollers","tag-powershell","tag-role-owner","tag-windows-2"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/1034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=1034"}],"version-history":[{"count":9,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/1034\/revisions"}],"predecessor-version":[{"id":1044,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/1034\/revisions\/1044"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=1034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=1034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=1034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}