加入收藏 | 设为首页 | 会员中心 | 我要投稿 孝感站长网 (https://www.0712zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 系统 > 正文

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

发布时间:2021-02-21 06:44:28 所属栏目:系统 来源:网络整理
导读:在 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

(编辑:孝感站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读