[英]Updating Active Directory user properties in Active Directory using Powershell
在使用Powershell v2.0的Windows Server 2003 R2环境中,如何复制Set-QADUser的功能来更新Active Directory中的用户属性,例如电话号码和标题?
诀窍在于,我想不依赖Set-QADUser来执行此操作,而且我还没有使用Server 2008的Commandlet的选项。
谢谢。
通过互联网将事物拼凑在一起,我想到了这个...
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相似,因为您使用的是相同的组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.