设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 服务器 > 系统 > 正文

windows – 使用Powershell在Active Directory中更新Active Dire

发布时间:2021-02-20 19:45 所属栏目:52 来源:网络整理
导读:在 Windows Server 2003 R2环境中,使用Powershell v2.0,如何复制 Set-QADUser的功能以更新Active Directory中的用户属性,如电话号码和标题? 这里的诀窍是,我想这样做而不依赖于Set-QADUser,但我没有选择使用Server 2008的命令行开关. 谢谢. 解决方法 从互联

在 Windows Server 2003 R2环境中,使用Powershell v2.0,如何复制 Set-QADUser的功能以更新Active Directory中的用户属性,如电话号码和标题?

这里的诀窍是,我想这样做而不依赖于Set-QADUser,但我没有选择使用Server 2008的命令行开关.

谢谢.

解决方法

从互联网上拼凑起来,我想出了这个……

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

更多信息

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

(编辑:ASP站长网)

    网友评论
    推荐文章
      热点阅读