{"id":2936,"date":"2010-07-04T10:25:26","date_gmt":"2010-07-04T06:25:26","guid":{"rendered":"http:\/\/msbro.ru\/?p=2936"},"modified":"2010-07-04T10:25:26","modified_gmt":"2010-07-04T06:25:26","slug":"powershell-sozdanie-lokalnogo-polzovatelya","status":"publish","type":"post","link":"https:\/\/msbro.ru\/index.php\/archives\/2936","title":{"rendered":"PowerShell: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f"},"content":{"rendered":"<p>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043a\u043e \u043c\u043d\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0438\u0441\u044c \u0441 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u043e  \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e  \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c \u0438 \u043f\u0430\u0440\u043e\u043b\u0435\u043c, \u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435  \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0434\u0432\u0443\u043c\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438: UserName \u0438 Password (\u041d\u0443 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c  \u0434\u0435\u043b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043d\u043e \u043d\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c ).<br \/>\n<!--more--><br \/>\n\u0412\u043e\u0442 \u0435\u0451 \u043a\u043e\u0434:<\/p>\n<pre>function  CreateUser ($Name, $Password)\r\n{\r\n    trap {\"Error creating user!\"; break} #\u041f\u0435\u0440\u0435\u0445\u0432\u0430\u0442 \u043e\u0448\u0438\u0431\u043e\u043a\r\n $computer = [ADSI]\"WinNT:\/\/$env:computername\" #\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0443 \u043f\u043e ADSI\r\n $user = $computer.Create(\"user\", $Name) #\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 user\r\n $user.SetPassword($Password) #\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u0430\u0440\u043e\u043b\u044c\r\n $user.SetInfo() #\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f            \r\n\r\n $UP = New-Object PSObject #\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\r\n $UP | Add-Member NoteProperty Username $Name #\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\r\n $UP | Add-Member NoteProperty Password $Password #\u0418 \u0435\u0449\u0451\r\n $UP #\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442\r\n}<\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<br \/>\n<code>PS C:\\Windows\\system32&gt; $Result = createUser -name Tester -pass  P@ssw0rd<br \/>\nPS C:\\Windows\\system32&gt; $Result<br \/>\nUsername Password<br \/>\n-------- --------<br \/>\nTester   P@ssw0rd<\/code><\/p>\n<p>PS C:\\Windows\\system32&gt; $Result.UserName<br \/>\nPS C:\\Windows\\system32&gt; $Result.Password<br \/>\nPS C:\\Windows\\system32&gt;<br \/>\n\u0421\u0442\u0440\u0430\u043d\u043d\u043e? \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0442\u043e \u0432\u0438\u0434\u043d\u043e 2 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430: UserName,  Password, \u0438 \u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f  \u044d\u0442\u0438\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u2026 \u043d\u0438\u0447\u0435\u0433\u043e. \u0412 \u0447\u0451\u043c \u0436\u0435 \u0434\u0435\u043b\u043e?<br \/>\n<code>PS C:\\Windows\\system32&gt; $Result.gettype().name<br \/>\nObject[]<br \/>\nPS C:\\Windows\\system32&gt; $Result.count<br \/>\n3<\/code><br \/>\n\u041a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0442\u0438\u043f\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043e \u0442\u043e\u043c \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e  \u043e\u0431\u044a\u0435\u043a\u0442, \u0430 \u043c\u0430\u0441\u0441\u0438\u0432. \u041f\u0440\u0438\u0447\u0435\u043c \u043a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e .Count \u2013 \u0438\u0437 \u0442\u0440\u0435\u0445  \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0417\u043d\u0430\u044f \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c:<br \/>\n<code>PS C:\\Windows\\system32&gt; $Result[2].Username<br \/>\nTester<br \/>\nPS C:\\Windows\\system32&gt; $Result[2].Password<br \/>\nP@ssw0rd<\/code><br \/>\n\u041d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u043b\u0438\u0448\u044c \u0442\u0440\u0435\u0442\u044c\u0438\u043c \u043f\u043e \u0441\u0447\u0451\u0442\u0443 (\u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0441  0). \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u0432\u0443\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<br \/>\n<code>PS C:\\Windows\\system32&gt; $Result[0].gettype().name<br \/>\nYou cannot call a method on a null-valued expression.<br \/>\nAt line:1 char:19<br \/>\n+ $Result[0].gettype &lt;&lt;&lt; $Result[0] -eq $null<br \/>\nTrue<\/code><br \/>\n\u0418\u0445 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e\u0447\u043d\u0435\u0435 \u043e\u043d\u0438 \u0440\u0430\u0432\u043d\u044b $null, \u043f\u0443\u0441\u0442\u043e\u0442\u0435. \u0410 \u0432\u0437\u044f\u043b\u0438\u0441\u044c \u043e\u043d\u0438  \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0432\u044b\u0437\u043e\u0432\u0430\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u0432 ADSI SetPassword() \u0438 SetInfo(). \u0423\u0436 \u043d\u0435 \u0437\u043d\u0430\u044e  \u0437\u0430\u0447\u0435\u043c, \u043d\u043e \u0432\u0438\u0434\u0438\u043c\u043e \u0430\u0432\u0442\u043e\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043b\u0438 \u044d\u0442\u043e \u043f\u0440\u0438\u043a\u043e\u043b\u044c\u043d\u044b\u043c   \u0410 \u0432 PowerShell \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u044c: \u0432\u0441\u0435  \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0443, \u0438  \u043d\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u2013 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u0432\u044b\u0432\u043e\u0434. \u0422\u043e \u0435\u0441\u0442\u044c  \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>function test {Get-process powershell; \"Test\"; del  c:\\test.txt; return 2+1; 2}<\/code> \u0432\u0435\u0440\u043d\u0451\u0442 \u0432\u0430\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437  \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0441\u0442\u0440\u043e\u043a\u0438 Test \u0438 \u0447\u0438\u0441\u043b\u0430 3. \u0414\u0432\u043e\u0439\u043a\u0430 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043d\u0435 \u0432\u0435\u0440\u043d\u0451\u0442\u0441\u044f \u043b\u0438\u0448\u044c  \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e return \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0439 \u0432\u044b\u0432\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0435  \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0430 \u043b\u0438\u0448\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0438\u0437 \u0440\u044f\u0434\u0430).<br \/>\n\u041a\u043e\u0440\u043e\u0447\u0435 \u0433\u043e\u0432\u043e\u0440\u044f \u0432 \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 $null\u2019\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0451\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438,  \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0435\u043d\u0438\u043b\u0438\u0441\u044c \u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439, \u0438 \u0432\u0441\u0451 \u0438\u0441\u043f\u043e\u0440\u0442\u0438\u043b\u0438   \u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e, \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f  \u043e\u0442 \u044d\u0442\u0438\u0445 $null\u2019\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440\u2026 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0432 \u0438\u0445 \u0432 Null<br \/>\n<code> $user.SetPassword($Password) | Out-Null<br \/>\n$user.SetInfo() | Out-Null<\/code><\/p>\n<p><a href=\"http:\/\/xaegr.wordpress.com\/2009\/11\/06\/create-localuser-and-null-in-output\/\" target=\"_blank\">\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043a\u043e \u043c\u043d\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u043b\u0438\u0441\u044c \u0441 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u043e \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c \u0438 \u043f\u0430\u0440\u043e\u043b\u0435\u043c, \u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0434\u0432\u0443\u043c\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438: UserName \u0438 Password (\u041d\u0443 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043d\u043e \u043d\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c ).<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,10],"tags":[17],"class_list":["post-2936","post","type-post","status-publish","format-standard","hentry","category-windows","category-scripts","tag-powershell"],"_links":{"self":[{"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/posts\/2936"}],"collection":[{"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/comments?post=2936"}],"version-history":[{"count":0,"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/posts\/2936\/revisions"}],"wp:attachment":[{"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/media?parent=2936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/categories?post=2936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/tags?post=2936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->