代码之家  ›  专栏  ›  技术社区  ›  Nathan Hartley

使用Powershell更新Active Directory中的Active Directory用户属性

  •  3
  • Nathan Hartley  · 技术社区  · 15 年前

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

    这里的诀窍是,我想在不依赖SETQADUSER的情况下完成这项工作,而且我还没有使用Server2008的Commandlet的选项。

    2 回复  |  直到 15 年前
        1
  •  6
  •   Nathan Hartley    15 年前

    把互联网上的东西拼凑在一起,我想到了这个。。。

    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
    

    更多信息

        2
  •  1
  •   jwmiller5    15 年前

    ADSI objects 在PowerShell中。语法看起来与vbscript类似,因为您使用的是相同的组件。