{"id":3158,"date":"2016-06-07T15:19:18","date_gmt":"2016-06-07T12:19:18","guid":{"rendered":"https:\/\/www.buldakov.ru\/?p=3158"},"modified":"2016-06-07T15:19:18","modified_gmt":"2016-06-07T12:19:18","slug":"%d0%9f%d0%be%d0%b8%d1%81%d0%ba-%d0%b8-%d0%b3%d0%bb%d0%be%d0%b1%d0%b0%d0%bb%d1%8c%d0%bd%d1%8b%d0%b9-%d0%ba%d0%b0%d1%82%d0%b0%d0%bb%d0%be%d0%b3","status":"publish","type":"post","link":"https:\/\/www.buldakov.ru\/?p=3158","title":{"rendered":"\u041f\u043e\u0438\u0441\u043a \u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433"},"content":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430: \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a guid-\u043e\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 AD, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0441\u0432\u043e\u0439\u0441\u0442\u0432. \u041e\u0431\u044a\u0435\u043a\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438, \u0442\u0430\u043a \u0438 \u0433\u0440\u0443\u043f\u043f\u0430\u043c\u0438 \u0438\u043b\u0438 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430\u043c\u0438. \u0418\u0441\u043a\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u043d\u043e\u0433\u043e\u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043b\u0435\u0441\u0430, \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0434\u043e\u043c\u0435\u043d\u0430 \u0432 \u043b\u0435\u0441\u0435. \u041d\u0430\u0439\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442, \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0435\u0433\u043e \u0442\u0438\u043f\u0430, \u043c\u043e\u0436\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u043b\u0435\u0442 Get-ADObject:<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">Get-ADObject $guid<\/pre>\n<p>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u0432\u0441\u0435\u043c \u0434\u043e\u043c\u0435\u043d\u0430\u043c \u043e\u0434\u043d\u043e\u0433\u043e \u043b\u0435\u0441\u0430. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u043b\u043e\u0431 &#8211; \u0432\u0437\u044f\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043e\u043c\u0435\u043d\u043e\u0432 \u0438 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u043d\u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043f\u043e\u0438\u0441\u043a:<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">$Domains = (Get-ADForest).Domains\r\n\r\nForEach ($Domain in $Domains)\r\n{\r\n$Search = Get-ADObject $guid -Server (Get-ADDomain $Domain).PDCEmulator -ErrorAction Stop\r\n}<\/pre>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u0442, \u043d\u043e \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043f\u043e-\u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 guid-\u0443 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u0434\u043e\u043c\u0435\u043d\u0430. \u041f\u043e\u0438\u0441\u043a \u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u043e\u043c\u0435\u043d\u0430\u0445 \u0432\u0435\u0440\u043d\u0451\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0430\u043c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0432\u043d\u0435\u0441\u0442\u0438 \u0432 \u0441\u043a\u0440\u0438\u043f\u0442 try-catch:<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">$Domains = (Get-ADForest).Domains\r\n$Results = @()\r\nForEach ($Domain in $Domains)\r\n{\r\n  try\r\n  {\r\n    $Search = Get-ADObject $guid -Server (Get-ADDomain $Domain).PDCEmulator -ErrorAction Stop\r\n    $Found = $true\r\n  }\r\n  catch\r\n  {\r\n    $Found = $false\r\n  }\r\n  If ($Found)\r\n  {\r\n    $Results += New-Object PSObject -Property @{\r\n    guid = $guid\r\n    Domain = $Domain\r\n    DistinguishedName = $Search.DistinguishedName\r\n    ObjectClass = $Search.ObjectClass\r\n    Found = $Found\r\n    }\r\n  }\r\n}<\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0438\u0437 txt-\u0444\u0430\u0439\u043b\u0430 \u0441\u043f\u0438\u0441\u043a\u0430 guid-\u043e\u0432:<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">$guids = Import-Csv -Path C:\\guids.txt\r\n$Domains = (Get-ADForest).Domains\r\n$Results = @()\r\nForEach ($guid in $guids)\r\n{\r\n  ForEach ($Domain in $Domains)\r\n  {\r\n    try\r\n    {\r\n      $Search = Get-ADObject $guid -Server (Get-ADDomain $Domain).PDCEmulator -ErrorAction Stop\r\n      $Found = $true\r\n    }\r\n    catch\r\n    {\r\n      $Found = $false\r\n    }\r\n    If ($Found)\r\n    {\r\n      $Results += New-Object PSObject -Property @{\r\n      guid = $guid\r\n      Domain = $Domain\r\n      DistinguishedName = $Search.DistinguishedName\r\n      ObjectClass = $Search.ObjectClass\r\n      Found = $Found\r\n      }\r\n    }\r\n  }\r\n}\r\n$Results | Where { $_.Found } | Select guid,Domain,DistinguishedName,ObjectClass,Found<\/pre>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0435\u043d\u0430 \u0438 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0438 \u0436\u0434\u0430\u0442\u044c. \u0415\u0441\u043b\u0438 \u0434\u043e\u043c\u0435\u043d\u043e\u0432 \u0443 \u043d\u0430\u0441 \u0441 \u0434\u0435\u0441\u044f\u0442\u043e\u043a, \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u043e\u0442\u043d\u0438, \u0442\u043e \u0436\u0434\u0430\u0442\u044c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0434\u043e\u043b\u0433\u043e. \u0427\u0442\u043e \u0441 \u044d\u0442\u0438 \u0434\u0435\u043b\u0430\u0442\u044c? \u0418\u0441\u043a\u0430\u0442\u044c \u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435! \u041f\u0440\u0430\u0432\u0434\u0430, \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435 \u0432\u0441\u0435 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0414\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u0442 \u0436\u0435 Get-ADObject, \u043d\u043e \u0432 \u043a\u043b\u044e\u0447\u0435 -Server \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433, \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u043f\u043e\u0440\u0442\u0443 3268:<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">$LocalSite = (Get-ADDomainController -Discover).Site\r\n$NewTargetGC = Get-ADDomainController -Discover -Service GlobalCatalog -SiteName $LocalSite\r\nif (!$NewTargetGC)\r\n{ $NewTargetGC = Get-ADDomainController -Discover -Service GlobalCatalog -NextClosestSite }\r\n$NewTargetGCHostName = $NewTargetGC.HostName\r\n$LocalGC = &quot;$NewTargetGCHostName&quot; + &quot;:3268&quot;<\/pre>\n<p>Try-catch \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0438\u0441\u043a\u0435 \u043d\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u043d\u0443\u0436\u0435\u043d \u0440\u0430\u0437\u0432\u0435 \u0447\u0442\u043e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 guid-\u043e\u0432. \u0421\u043a\u0440\u0438\u043f\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u0441\u044f:<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">$guids = Import-Csv -Path C:\\guids.txt\r\n$Results = @()\r\n$LocalSite = (Get-ADDomainController -Discover).Site\r\n$NewTargetGC = Get-ADDomainController -Discover -Service GlobalCatalog -SiteName $LocalSite\r\nif (!$NewTargetGC)\r\n{ $NewTargetGC = Get-ADDomainController -Discover -Service GlobalCatalog -NextClosestSite }\r\n$NewTargetGCHostName = $NewTargetGC.HostName\r\n$LocalGC = &quot;$NewTargetGCHostName&quot; + &quot;:3268&quot;\r\nForEach ($guid in $guids) \r\n{\r\n  Try \r\n  {\r\n    $Search = Get-ADObject -Identity $guid.guid -Server $LocalGC\r\n  }\r\n  Catch {\r\n  }\r\n  $Results += New-Object PSObject -Property @{\r\n  guid = $guid.guid\r\n  DistinguishedName = $Search.DistinguishedName\r\n  ObjectClass = $Search.ObjectClass\r\n  }\r\n}\r\n$Results | Select guid,DistinguishedName,ObjectClass<\/pre>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 \u043f\u0430\u0440\u0443 \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u0432 \u0431\u044b\u0441\u0442\u0440\u0435\u0435.<\/p>\n<p><span style=\"text-decoration: underline;\">\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/span>:<br \/>\n<a href=\"http:\/\/blogs.metcorpconsulting.com\/tech\/?p=1339\" target=\"_blank\">Powershell Code: Discover a Local Global Catalog for Forest Queries<\/a><br \/>\n<a href=\"https:\/\/adsecurity.org\/?p=354\" target=\"_blank\">PowerShell Code: Find User in Active Directory Forest<\/a><br \/>\n<a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/ee617217.aspx\" target=\"_blank\">Get-ADDomainController<\/a><br \/>\n<a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/ee617198.aspx\" target=\"_blank\">Get-ADObject<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430: \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a guid-\u043e\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 AD, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0441\u0432\u043e\u0439\u0441\u0442\u0432. \u041e\u0431\u044a\u0435\u043a\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438, \u0442\u0430\u043a \u0438 \u0433\u0440\u0443\u043f\u043f\u0430\u043c\u0438 \u0438\u043b\u0438 \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u0430\u043c\u0438. \u0418\u0441\u043a\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u043d\u043e\u0433\u043e\u0434\u043e\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043b\u0435\u0441\u0430, \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u043b\u044e\u0431\u043e\u0433\u043e \u0434\u043e\u043c\u0435\u043d\u0430 \u0432 \u043b\u0435\u0441\u0435. \u041d\u0430\u0439\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442, \u0432\u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0435\u0433\u043e \u0442\u0438\u043f\u0430, \u043c\u043e\u0436\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u043b\u0435\u0442 Get-ADObject: Get-ADObject $guid \u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[7,11],"tags":[],"class_list":["post-3158","post","type-post","status-publish","format-standard","hentry","category-powershell","category-life"],"_links":{"self":[{"href":"https:\/\/www.buldakov.ru\/index.php?rest_route=\/wp\/v2\/posts\/3158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.buldakov.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buldakov.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buldakov.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buldakov.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3158"}],"version-history":[{"count":4,"href":"https:\/\/www.buldakov.ru\/index.php?rest_route=\/wp\/v2\/posts\/3158\/revisions"}],"predecessor-version":[{"id":3162,"href":"https:\/\/www.buldakov.ru\/index.php?rest_route=\/wp\/v2\/posts\/3158\/revisions\/3162"}],"wp:attachment":[{"href":"https:\/\/www.buldakov.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buldakov.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buldakov.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}