开发者

Updating Active Directory user properties in Active Directory using Powershell

In a Windows Server 2003 R2 environment, using Powershell v2.0, how would one duplicate the functionality of Set-QADUser to update user properties in Active Directory, like their phone number and title?

The trick here being, I would like to do this without开发者_如何转开发 depending on Set-QADUser and I do not have the option to use the Server 2008's commandlets, yet.

Thanks.


Piecing things together from around the internet, I came up with this...

function Get-ADUser( [string]$samid=$env:username){
     $searcher=New-Object DirectoryServices.DirectorySearcher
     $searcher.Filter="(&(objectcategory=person)(objectclass=user)(sAMAccountname=$samid))"
     $user=$searcher.FindOne()
      if ($user -ne $null ){
          $user.getdirectoryentry()
     }
}

$user = Get-ADUser 'UserName'

# Output all properties
$user.psbase.properties

# Change some properties
$user.title = 'New Title'
$user.telephoneNumber = '5555551212'
$user.SetInfo()

# Output the results
$user.title
$user.telephoneNumber

More Information

  • Using PowerShell to work with ADSI to manage an Active Directory environment
  • SelfADSI : The ADSI Scripting Tutorial / The LDAP Scripting Tutorial
  • IADsUser Interface


You will want to use the ADSI objects in PowerShell. The syntax is going to look similar to vbscript because you are using the same component.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜