{"id":20,"date":"2017-08-02T15:29:40","date_gmt":"2017-08-02T12:29:40","guid":{"rendered":"http:\/\/itbru.ru\/?p=20"},"modified":"2018-06-20T11:13:46","modified_gmt":"2018-06-20T08:13:46","slug":"powershell-sozdanie-spiska-userov","status":"publish","type":"post","link":"https:\/\/itbru.ru\/index.php\/2017\/08\/02\/powershell-sozdanie-spiska-userov\/","title":{"rendered":"PowerShell. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u0430\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0430\u043f\u043a\u0435."},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-16 alignleft\" src=\"https:\/\/itbru.ru\/wp-content\/uploads\/2017\/08\/images.png\" alt=\"\" width=\"122\" height=\"137\" \/>\u0417\u0430\u0434\u0430\u0447\u0430 \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c \u043a\u0442\u043e \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0434\u043e\u043c\u0435\u043d\u0430 \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u043f\u0430\u043f\u043a\u0435 \u0438 \u043a\u0430\u043a\u0438\u043c\u0438 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442.<!--more-->\u0415\u0441\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f \u0438\u043c\u0435\u044e\u0442 \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438. \u041d\u043e \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043c\u043d\u043e\u0433\u043e, \u0434\u0430 \u0435\u0449\u0435 \u0438 \u0441 \u0433\u0440\u0443\u043f\u043f\u0430\u043c\u0438, \u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430.<\/p>\n<p>\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0430\u043f\u043a\u0435, \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043e\u0442 \u0433\u0440\u0443\u043f\u043f, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0445\u043e\u0434\u044f\u0442 \u0432 \u0433\u0440\u0443\u043f\u043f\u044b \u0438 \u0432\u044b\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u043e \u0432 \u0443\u0434\u043e\u0431\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0439 \u0444\u043e\u0440\u043c\u0435.<\/p>\n<p>\u041d\u044e\u0430\u043d\u0441\u044b:<\/p>\n<p>\u041c\u0435\u043d\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0435 \u0443\u0447\u0435\u0442\u043a\u0438, \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u0430\u0442\u044c \u0433\u0440\u0443\u043f\u043f\u044b \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u043b\u0435\u0442\u0430 Get-ADObject \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 ObjectClass &#171;User&#187; \u0438\u043b\u0438 &#171;Group&#187; \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u043b\u0438 \u0433\u0440\u0443\u043f\u043f\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:ps decode:true\">#\r\n#\u0421\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0445 \u0443\u0447\u0435\u0442\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u043f\u0430\u043f\u043a\u0443. \u0421\u043f\u0438\u0441\u043e\u043a \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0432 CSV \u0444\u0430\u0439\u043b. \r\n#\r\n#\u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0430\u043f\u043a\u0443 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0443\u0436\u0435\u043d \u043e\u0442\u0447\u0435\u0442\r\n$path = \u201c\u043f\u0443\u0442\u044c \u0434\u043e \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043f\u0430\u043f\u043a\u0438. \u0414\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0435\u0442\u0435\u0432\u0443\u044e \u043f\u0430\u043f\u043a\u0443\u201d\r\n#\u043f\u0443\u0442\u044c \u043a\u0443\u0434\u0430 \u043a\u043b\u0430\u0442\u044c CSV\r\n$datafile = \"c:\\AccessRights.csv\"\r\n#\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u043f\u043e \u043f\u0443\u0442\u0438 $datafile\r\nSet-Content -Value '\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f;\u041f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430;' -Path $datafile -Encoding UTF8\r\n#\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u0434\u043e\u043c\u0435\u043d\u0430\r\n$domain = (Get-ADDomain).name.ToUpper()\r\n#\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043f\u0430\u043f\u043a\u0438\r\n$Acl = Get-Acl $path\r\n$acl = $acl.Access\r\n#\u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043e\u0441\u0442\u0443\u043f\u0430\r\nforeach ($a in $acl)\r\n{\r\n#\u0411\u0435\u0440\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0435 \u0443\u0447\u0435\u0442\u043a\u0438\r\nif ($a.IdentityReference -match $domain)\r\n{\r\n#\u041f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u043c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043d\u0430 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u0438\u0439)\r\nif ($a.FileSystemRights.ToString() -eq \"ReadAndExecute, Synchronize\") {$AccessType = \"\u0422\u043e\u043b\u044c\u043a\u043e \u0427\u0442\u0435\u043d\u0438\u0435\"}\r\nelseif ($a.FileSystemRights.ToString() -eq \"Modify, Synchronize\") {$AccessType = \"\u0427\u0442\u0435\u043d\u0438\u0435 \u0438 \u0417\u0430\u043f\u0438\u0441\u044c\"}\r\nelseif ($a.FileSystemRights.ToString() -eq \"FullControl\") {$AccessType = \"\u041f\u043e\u043b\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\"}\r\nelse {$AccessType = \"Custom\"}\r\n$name = $a.IdentityReference.Value.ToString().Replace($domain+\"\\\",'')\r\n#\u0412\u044b\u044f\u0441\u043d\u044f\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0430 \u0438\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\r\n$ADObject = Get-ADObject -filter{SamAccountName -eq $name}\r\nif ($ADObject.ObjectClass.ToString() -eq \"user\") {$data = $name+\";\"+$AccessType}\r\n#\u0415\u0441\u043b\u0438 \u0433\u0440\u0443\u043f\u043f\u0430 - \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0433\u0440\u0443\u043f\u043f\u0435\r\nif ($ADObject.ObjectClass.ToString() -eq \"group\") \r\n{\r\n$users = Get-ADGroupMember $name\r\nforeach ($u in $users)\r\n{\r\n$name = $u.SamAccountName\r\n$data = $name+\";\"+$AccessType \r\n#\u0417\u0430\u043f\u0438\u0441\u044c \u0432 \u0444\u0430\u0439\u043b\r\nAdd-Content -Value $data -Path $DataFile -Encoding UTF8\r\n}\r\n}\r\n#\u0417\u0430\u043f\u0438\u0441\u044c \u0432 \u0444\u0430\u0439\u043b\r\nAdd-Content -Value $data -Path $DataFile -Encoding UTF8\r\n}\r\n\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c \u043a\u0442\u043e \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0434\u043e\u043c\u0435\u043d\u0430 \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u043f\u0430\u043f\u043a\u0435 \u0438 \u043a\u0430\u043a\u0438\u043c\u0438 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/itbru.ru\/index.php\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itbru.ru\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itbru.ru\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itbru.ru\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itbru.ru\/index.php\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":3,"href":"https:\/\/itbru.ru\/index.php\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":173,"href":"https:\/\/itbru.ru\/index.php\/wp-json\/wp\/v2\/posts\/20\/revisions\/173"}],"wp:attachment":[{"href":"https:\/\/itbru.ru\/index.php\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itbru.ru\/index.php\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itbru.ru\/index.php\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}