2012-05-24 5 views
2

powershell을 사용하여 새 사용자를 만들려고합니다. 우리는 Active Directory를 실행하지 않습니다 (변경 사항이 있는지 여부는 확실하지 않음). 다음은 내가하려는 일입니다.powershell에서 ADSI를 사용하여 특성을 설정할 수 없습니다.

$machine = [ADSI]"WinNT://localhost,computer" 
$newUser = $machine.Create("User", $Username) 
$newUser.setpassword($Password) 
$newUser.SetInfo() 

이 시점까지 모든 것이 작동하고 사용자가 생성됩니다. 하지만 지금은이 같은 추가 설정을 변경하려면,하지만 그들은 모두이 내가

Exception calling "Put" with "2" argument(s): "Exception from HRESULT: 0x8000500F" 

난 어떤 생각을지고있어 오류가

$newUser.Put("sAMAcountName", $Username) 
$newUser.SetInfo() 

$newUser.Put("userAccountControl", 0x10000) 
$newUser.SetInfo() 

UPDATE

실패 잘못하고있는거야? 감사!

솔루션

JPBlanc의 대답은 올바른 방향으로 날 지점 수있었습니다.

가장 큰 문제는 Active Directory 도메인의 일부가 아닌 컴퓨터에서 [ADSI]을 사용하는 것에 대한 설명서가 거의 없기 때문입니다.

UserFlags 속성을 사용하여 문제를 해결할 수있었습니다.

$newUser.UserFlags = $UserFlags.DONT_EXPIRE_PASSWD 
$newUser.CommitChanges() 

답변

0

표시되는 오류 메시지는 무엇입니까? 사용자를 다시 수정하려면 먼저 새 참조를 가져와야합니다.

3

당신은 관리자로 사용해 볼 수 : 내가 볼 은어 따라와 코드에 따르면

$obj = [ADSI]"WinNT://$env:COMPUTERNAME" 
$user = $obj.Children.find("utilisateur1") 
$user.psbase.rename("user1") 
$user.put('FullName','user1') 
$user.setinfo() 

AD 사용자 인 sAMAcountName 또는 userAccountControl 속성 :

PS C:\Windows\system32> $a | fl * 


UserFlags     : {513} 
MaxStorage     : {-1} 
PasswordAge    : {917} 
PasswordExpired   : {0} 
LoginHours     : {255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255} 
FullName     : {user1} 
Description    : {} 
BadPasswordAttempts  : {0} 
HomeDirectory    : {} 
LoginScript    : {} 
Profile     : {} 
HomeDirDrive    : {} 
Parameters     : {} 
PrimaryGroupID    : {513} 
Name      : {user1} 
MinPasswordLength   : {0} 
MaxPasswordAge    : {3628800} 
MinPasswordAge    : {0} 
PasswordHistoryLength  : {0} 
AutoUnlockInterval   : {1800} 
LockoutObservationInterval : {1800} 
MaxBadPasswordsAllowed  : {0} 
objectSid     : {1 5 0 0 0 0 0 5 21 0 0 0 151 181 85 95 2 227 17 190 248 24 47 102 18 4 0 0} 
AuthenticationType   : Secure 
Children     : {} 
Guid      : {D83F1060-1E71-11CF-B1F3-02608C9E7553} 
ObjectSecurity    : 
NativeGuid     : {D83F1060-1E71-11CF-B1F3-02608C9E7553} 
NativeObject    : System.__ComObject 
Parent      : WinNT://WORKGROUP/JPBHPP2 
Password     : 
Path      : WinNT://WORKGROUP/JPBHPP2/user1 
Properties     : {UserFlags, MaxStorage, PasswordAge, PasswordExpired...} 
SchemaClassName   : User 
SchemaEntry    : System.DirectoryServices.DirectoryEntry 
UsePropertyCache   : True 
Username     : 
Options     : 
Site      : 
Container     : 


PS C:\Windows\system32> $a | select -ExpandProperty properties 

PropertyName              Value 
------------              ----- 
UserFlags               513 
MaxStorage               -1 
PasswordAge              917 
PasswordExpired              0 
LoginHours          {255, 255, 255, 255...} 
FullName               user1 
Description 
BadPasswordAttempts             0 
HomeDirectory 
LoginScript 
Profile 
HomeDirDrive 
Parameters 
PrimaryGroupID              513 
Name                user1 
MinPasswordLength             0 
MaxPasswordAge             3628800 
MinPasswordAge              0 
PasswordHistoryLength            0 
AutoUnlockInterval            1800 
LockoutObservationInterval          1800 
MaxBadPasswordsAllowed            0 
objectSid            {1, 5, 0, 0...} 
관련 문제