【发布时间】:2014-11-20 06:13:26
【问题描述】:
我正在清除计算机的 AD 属性。 然后我尝试将该属性更改为某个值。但是,当我查看该 AD 对象的属性时,该属性似乎不再存在:
function clearAttribute
{
$directorySearcher = New-Object System.DirectoryServices.DirectorySearcher
$directorySearcher.PageSize = 100
$directorySearcher.SearchScope = [System.DirectoryServices.SearchScope]::Subtree
$directorySearcher.Filter = "(&(objectCategory=computer)(cn=computerName1))"
$result = $directorySearcher.FindOne()
if ($result.Properties.Contains("netbootmachinefilepath"))
{
$directoryEntry = $result.GetDirectoryEntry()
$directoryEntry.Properties["netbootmachinefilepath"].Clear()
$directoryEntry.CommitChanges()
}
}
function setAttribute
{
$directorySearcher = New-Object System.DirectoryServices.DirectorySearcher
$directorySearcher.PageSize = 100
$directorySearcher.SearchScope = [System.DirectoryServices.SearchScope]::Subtree
$directorySearcher.Filter = "(&(objectCategory=computer)(cn=computerName1))"
$result = $directorySearcher.FindOne()
if ($result.Properties.Contains("netbootmachinefilepath")) ###THIS IS FALSE!###
{
$directoryEntry = $result.GetDirectoryEntry()
$directoryEntry.Properties["netbootmachinefilepath"].Value = "someValue"
$directoryEntry.CommitChanges()
}
}
clearAttribute
setAttribute
编辑:原来这个属性可以是非空白或删除(它不能是空白)。在“清除”它之后,如果要更新值,就必须重新创建它。
【问题讨论】:
标签: powershell active-directory