English 中文(简体)
(ADSI):存在者抛出一个例外 而不是返回假
原标题:[ADSI]::Exists throws an exception instead of returning False

如果 ADSI 对象不存在, 我正试图用它创建一个用户。 以下是我得到的奇怪的结果

#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"

最后一行对我来说没有意义。 为什么它会提出一个例外, 当我具体说明我具体在找一个用户, 但当我指定我需要一个用户时, 它会很好地发挥作用? 这对我来说似乎完全不直观。 我错过了什么?

最佳回答

一只虫子,微软不能修复它。

问题回答

暂无回答




相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

How to transpose data in powershell

I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...