我正在使用带有PowerShell v2.0的Windows 7工作站进行工作,并尝试从启用LostAndFound
了Active Directory回收站的2008 R2 FL林和域中的容器中删除特定(孤立的)对象,但没有运气用什么。
重要的是,我需要删除该对象,并且仅删除该对象(而不是删除具有该IsDeleted
属性的每个对象,这似乎是我可以找到的全部帮助)。
我需要删除它,因为为了解决断开的信任关系,计算机已与域断开连接(大概是导致对象先进入回收站,然后再进入LostAndFound
容器),并且我们想给它其原始名称返回(基于PC上的资产标签号)。尝试将计算机重新加入具有正确名称的域失败,并显示以下错误消息(The specified account does not exist
)
并尝试将其重命名为正确的名称后,该操作失败,并显示以下错误消息(The account already exists
)
因此实际的PC当前坐在那里的名称不正确,我需要纠正该名称。
但是,尝试删除此AD对象会产生错误:The specified account does not exist
。该对象的可分辨名称中包含一个\
(反斜杠)字符,我认为这是由于它位于LostAndFound
容器中,我想知道这是否是问题所在……以及如何修复它。我将外壳程序运行为domain admin
,验证了该domain admins
组对相关对象具有完全控制权和所有权,并且似乎无法弄清楚该对象。
有问题的对象(已编辑)
Get-ADObject "CN=SomeComputer\0ADEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv" -IncludeDeletedObjects -Properties *
accountExpires : 9223372036854775807
CanonicalName : MyEmployer.prv/LostAndFound/SomeComputer
DEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6
CN : SomeComputer
DEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6
codePage : 0
countryCode : 0
Created : 12/7/2012 9:25:30 PM
createTimeStamp : 12/7/2012 9:25:30 PM
Deleted :
Description : HP6300
DisplayName :
DistinguishedName : CN=SomeComputer\0ADEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=
prv
dNSHostName : SomeComputer.MyEmployer.prv
dSCorePropagationData : {5/21/2014 1:40:31 PM, 12/31/1600 7:00:00 PM}
instanceType : 4
isCriticalSystemObject : False
isDeleted :
LastKnownParent : OU=Workstations,OU=Computers,OU=One of Our Sites,DC=MyEmployer,DC=prv
lastLogonTimestamp : 130451668084269817
localPolicyFlags : 0
memberOf : {CN=PCMilerComputers,DC=MyEmployer,DC=prv}
Modified : 5/21/2014 1:40:54 PM
modifyTimeStamp : 5/21/2014 1:40:54 PM
msDS-LastKnownRDN : SomeComputer
Name : SomeComputer
DEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6
nTSecurityDescriptor : System.DirectoryServices.ActiveDirectorySecurity
ObjectCategory :
ObjectClass : computer
ObjectGUID : 90a13eaa-c7b0-4258-bebb-87b7aed39ec6
objectSid : S-1-5-21-1708945318-605057401-313073093-5882480
operatingSystem : Windows 7 Enterprise
operatingSystemServicePack : Service Pack 1
operatingSystemVersion : 6.1 (7601)
primaryGroupID : 515
ProtectedFromAccidentalDeletion : False
pwdLastSet : 130451667147545072
sAMAccountName : SomeComputer$
sDRightsEffective : 15
servicePrincipalName : {HOST/SomeComputer, HOST/SomeComputer.MyEmployer.prv}
userAccountControl : 4096
userCertificate : [Not included]
uSNChanged : 54007434
uSNCreated : 5004556
whenChanged : 5/21/2014 1:40:44 PM
whenCreated : 12/7/2012 9:25:30 PM
我尝试过的所有方法似乎都无效,并且尝试了很多。关于这一点,我在下面尝试过。
首先,使用简单的一行PowerShell cmdlet:
Get-ADObject "CN=SomeComputer\0ADEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv" -IncludeDeletedObjects | Remove-ADObject
Confirm
Are you sure you want to perform this action?
Performing operation "Remove" on Target
"CN=SomeComputer\0ADEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y
Remove-ADObject : The specified account does not exist
At line:1 char:145
+ Get-ADObject "CN=SomeComputer\0ADEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv" -IncludeDeletedObjects | Remove-ADObject <<<<
+ CategoryInfo : NotSpecified: (CN=SomeComputer\0ADE...MyEmployer,DC=prv:ADObject) [Remove-ADObject], ADException
+ FullyQualifiedErrorId : The specified account does not exist,Microsoft.ActiveDirectory.Management.Commands.RemoveADObject
然后,同样地,引用GUID。
Get-ADObject "90a13eaa-c7b0-4258-bebb-87b7aed39ec6" -IncludeDeletdObjects | Remove-ADObject
Confirm
Are you sure you want to perform this action?
Performing operation "Remove" on Target
"CN=SomeComputer\0ADEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y
Remove-ADObject : The specified account does not exist
At line:1 char:94
+ Get-ADObject "90a13eaa-c7b0-4258-bebb-87b7aed39ec6" -IncludeDeletedObjects | Remove-ADObject <<<<
+ CategoryInfo : NotSpecified: (CN=SomeComputer\0ADE...MyEmployer,DC=prv:ADObject) [Remove-ADObject], ADException
+ FullyQualifiedErrorId : The specified account does not exist,Microsoft.ActiveDirectory.Management.Commands.RemoveADObject
然后,首先将值读入变量。(尝试使用GUID和DN,仅显示一个,因为它们产生相同的错误)。
$blah = "90a13eaa-c7b0-4258-bebb-87b7aed39ec6"
Get-ADObject $blah -IncludeDeletedObjects | Remove-ADObject
Confirm
Are you sure you want to perform this action?
Performing operation "Remove" on Target
"CN=SomeComputer\0ADEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y
Remove-ADObject : The specified account does not exist
At line:1 char:60
+ Get-ADObject $blah -IncludeDeletedObjects | Remove-ADObject <<<<
+ CategoryInfo : NotSpecified: (CN=SomeComputer\0ADE...MyEmployer,DC=prv:ADObject) [Remove-ADObject], ADException
+ FullyQualifiedErrorId : The specified account does not exist,Microsoft.ActiveDirectory.Management.Commands.RemoveADObject
然后,我觉得我可以忍受不得不调用DSRM而不是本地执行。
dsrm "CN=SomeComputer\0ADEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=Lost
AndFound,DC=MyEmployer,DC=prv"
Are you sure you wish to delete CN=SomeComputer\0ADEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv
(Y/N)? y
dsrm failed:CN=SomeComputer\0ADEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv:The specified account does not exist.
然后我对使它变得可自动化说了地狱,我将右键单击并通过ADSIedit将其删除。
所以,最后,我吞下我的骄傲并在这里问。 我该如何摆脱这个该死的东西? 它显然存在,并且它的存在正在引起问题,但是我所有从Active Directory删除它的尝试都遇到了谎言,该死的谎言和错误消息。
更新:
根据ServerFaulters的评论,建议和讨论,其他无效的事情:
转义0
,就像\0
代表一个空字节一样。
Get-ADObject "CN=SomeComputer`0ADEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv" -IncludeDeletedObjects | Remove-ADObject
Get-ADObject : No superior reference has been configured for the directory service. The directory service is therefore unable to issue referrals to objects outside this forest
At line:1 char:13
+ Get-ADObject <<<< "CN=SomeComputer`0ADEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv" -Includ
eDeletedObjects | Remove-ADObject
+ CategoryInfo : NotSpecified: (CN=SomeComputer ADEL...MyEmployer,DC=prv:ADObject) [Get-ADObject], ADException
+ FullyQualifiedErrorId : No superior reference has been configured for the directory service. The directory service is therefore unable to issue referrals to objects outside this forest,Microsoft.ActiveDirectory.Management.Commands.GetADObject
转义整个字符\0A
,就像是回车符或换行符一样,就像在DOS中一样(尝试使用`n,`r,`n`r和`r`n)。全部返回相同的错误,因此仅显示一次。
Get-ADObject "SomeComputer`n`rDEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv" -IncludeDeletedObjects | Remove-ADObject
Get-ADObject : The object name has bad syntax
At line:1 char:13
+ Get-ADObject <<<< "CN=SomeComputer`n`rDEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv" -IncludeDeletedObjects | Remove-ADObject
+ CategoryInfo : NotSpecified: (CN=SomeComputer
DEL...MyEmployer,DC=prv:ADObject) [Get-ADObject], ADException
+ FullyQualifiedErrorId : The object name has bad syntax,Microsoft.ActiveDirectory.Management.Commands.GetADObject
转义\0A
为换页(是的,有点绝望)。
Get-ADObject "CN=SomeComputer`fDEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv" -IncludeDeletedObjects | Remove-ADObject
Get-ADObject : Directory object not found
At line:1 char:13
+ Get-ADObject <<<< "CN=SomeComputer`fDEL:90a13eaa-c7b0-4258-bebb-87b7aed39ec6,CN=LostAndFound,DC=MyEmployer,DC=prv" -IncludeDeletedObjects | Remove-ADObject
+ CategoryInfo : ObjectNotFound: (CN=SomeComputer♀DEL:...MyEmployer,DC=prv:ADObject) [Get-ADObject], ADIdentityNotFoundException
+ FullyQualifiedErrorId : Directory object not found,Microsoft.ActiveDirectory.Management.Commands.GetADObject
然后,我想出了应该确定该 \0A
字符是否是问题所在,因此我在广告回收站中选择了一个我不关心的对象,并在其中插入了\0A
字符串,并试图将其吹走。有效。
Get-ADObject -Filter { Name -Like '*DEL:*' } -IncludeDeletedObjects | Remove-ADObject
Confirm
Are you sure you want to perform this action?
Performing operation "Remove" on Target "CN=SomeServer-SomeJackass HP LaserJet 1320
PS\0ADEL:eddb23e7-b8d8-4d00-801f-22d82c169d66,CN=Deleted Objects,DC=MyEmployer,DC=prv".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y
Confirm
Are you sure you want to perform this action?
Performing operation "Remove" on Target "CN=SomeServer-SomeJackass HP LaserJet 1320 PCL
5e\0ADEL:6e72e78f-f110-492c-ad50-91107f6fbd6a,CN=Deleted Objects,DC=MyEmployer,DC=prv".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y
$C = Get-ADObject -Filter { Name -Like '*DEL:*' }
只返回你的孤儿?如果是这样,Remove-ADObject -Identity $C.DistinguishedName
那那\0
是一个空终止符。
The specified account does not exist
错误。对于它的价值,我也尝试将其\0
视为空字节(并转义),以及将其\A0
视为回车/换行符(与DOS中一样),也没有任何乐趣。在猜测和逃避各种尝试\A0
人物遭到了The object name has bad syntax
和Directory object not found
。:(
'*CNF:*'
)上使用该技术,并且效果很好。