Updating Active Directory user properties in Active Directory using Powershell

▼魔方 西西 提交于 2019-12-04 13:51:23

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!