在 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
更多信息
您将需要在 PowerShell中使用ADSI 对象。语法看起来与 vbscript 相似,因为您使用的是相同的组件。