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"
最後一行對我沒有意義。爲什麼當我指定我特別尋找一個用戶時會拋出異常,但是當我不指定我想要一個用戶時它工作得很好?這對我來說似乎完全不直觀。我錯過了什麼?