4
我想创建一个用户使用ADSI对象,如果它不存在。这里是我得到的奇怪结果[ADSI] ::存在抛出一个异常,而不是返回False
#Check a user that I know exists
[ADSI]::Exists("WinNT://localhost/micah,user") #True
#Check a group that I know exists
[ADSI]::Exists("WinNT://localhost/administrators,group") #True
#Check a group that DOESN'T exist
[ADSI]::Exists("WinNT://localhost/whoops,group") #False
#Check a user that DOESN'T exist (NOT specifying that the obect is a user)
[ADSI]::Exists("WinNT://localhost/test") #False (This works fine)
#Check a user that DOESN'T exist (specifying that the obect IS a user)
[ADSI]::Exists("WinNT://localhost/test,user")
#Throws exception "The user name could not be found"
最后一行对我没有意义。为什么当我指定我特别寻找一个用户时会抛出异常,但是当我不指定我想要一个用户时它工作得很好?这对我来说似乎完全不直观。我错过了什么?