windows 使用 Powershell 更新 Active Directory 中的 Active Directory 用户属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2184692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Updating Active Directory user properties in Active Directory using Powershell
提问by Nathan Hartley
In a Windows Server 2003 R2 environment, using Powershell v2.0, how would one duplicate the functionality of Set-QADUserto update user properties in Active Directory, like their phone number and title?
在 Windows Server 2003 R2 环境中,使用 Powershell v2.0,如何复制Set-QADUser的功能来更新 Active Directory 中的用户属性,如电话号码和职位?
The trick here being, I would like to do this without depending on Set-QADUser and I do not have the option to use the Server 2008's commandlets, yet.
这里的诀窍是,我想在不依赖 Set-QADUser 的情况下执行此操作,而且我还没有使用 Server 2008 的命令行开关的选项。
Thanks.
谢谢。
回答by Nathan Hartley
Piecing things together from around the internet, I came up with this...
把互联网上的东西拼凑起来,我想出了这个......
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
More Information
更多信息
回答by jwmiller5
You will want to use the ADSI objectsin PowerShell. The syntax is going to look similar to vbscript because you are using the same component.
您将需要在 PowerShell 中使用ADSI 对象。语法看起来类似于 vbscript,因为您使用的是相同的组件。