Powershell FindAll()ComException

时间:2014-08-04 16:35:30

标签: powershell ldap findall sccm directorysearcher

我有一个PowerShell脚本,我们在Microsoft SCCM PXE任务序列中使用它来命名PC。在主服务器管理员最近升级到SCCM 2012 R2之前,它一直运行良好。

现在,当代码运行时,搜索用户是否在完成PXE构建所需的指定AD组中,则会出现此COM错误

Exception calling "FindAll" with "0" argument(s): "Unknown error (0x80005000)"
At X:\Windows\System32\OSD\x86_PXE.ps1:202 char:1
+ $colResults = $objSearcher.FindAll()    # Finds all items that match search and put ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : COMException

我已经进行了广泛的搜索,试图解决这个问题。这似乎是一个.Net错误,但我没有成功解决它。

以下是相关代码。请注意,这是在SCCM 2012 R2附带的Windows PE以及当前的Windows ADK中运行的。它很可能在普通PC上运行得很好,就像在我的PC上一样。

需要注意的是,您需要更改以匹配您的环境

  • $ Domain
  • $ strFilter - 特别是“Memberof = cn =”
  • $ objOU - 服务器路径

function get-humadcreds {
    $global:creds = get-credential -message "Please authenticate to Domain"
    $global:UserName = $creds.username
    $global:encPassword = $creds.password
    $password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($encpassword))   # Converts secure string to plain text
    $Domain = #Domain

Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain
$pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext $ct,$Domain
$authed = $pc.ValidateCredentials($UserName,$Password)

# Recursively requests credentials if authorization fails
if ($authed -eq $false) {
    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [System.Windows.Forms.MessageBox]::Show("Authentication failed - please retry!")
    get-humadcreds
}
}

get-humadcreds # Gets AD credentials from user

###Provisioning Authentication
$strFilter = "(&(objectCategory=user)(SAMACCOUNTNAME=$global:UserName)(|(Memberof=cn=,OU=Delegation,OU=,dc=,dc=,dc=)))"     # Filter for searching
$decodedpassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($encpassword))        # Decoded password from AD Auth
$objOU = New-Object System.DirectoryServices.DirectoryEntry("LDAP://server/OU=,dc=,dc=,dc=",$global:username,$decodedpassword)          # Authentication must specify domain controller
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objOU        # Starts search in this OU
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter        # Applies filter to search
$objSearcher.SearchScope = "Subtree"
$colProplist = "name"
$isInProvGroup = $False                 # Defaults value to false.
echo $objSearcher >> X:\Windows\System32\OSD\results.txt    
$colResults = $objSearcher.FindAll() # Finds all items that match search and puts them in array $colResults
echo $colResults
foreach ($objResult in $colResults){
    $isInProvGroup=$True                #If user is in a group to add PCs (if $colResults is not empty), result will be true


}
echo $isInProvGroup

PE OS Verson 6.3.9600.16384

Added Components

1 个答案:

答案 0 :(得分:0)

Welp ..找到了我的答案,于8月11日修好了。 Reddit thread

以前在R2之前的SCCM 2012中,启动映像是Windows 8 PE4映像,我们必须将ADSI集成回使用Johan Arwidmark编写的版本。可以找到here作为参考。

这次在R2更新之后,随后将启动映像强制升级到8.1 PE5,因为没有先前的启动映像从PXE启动,我们不得不再次从here添加ADSI。以前和这次它是通过驱动程序下的配置管理器完成的,它作为驱动程序添加了所需的文件,并作为驱动程序组件添加到boot.wim中,但实际上经过挖掘很长一段时间后我发现它不是'实际上,即使操作返回成功,也会将所需的dll文件添加到图像中。

我最终做的是使用DISM在我的电脑上手动安装wim文件,从文件夹添加驱动程序,允许安装未签名的驱动程序。然后手动验证dll被放入 放在已挂载的System32文件夹中。在我这样做之后,我能够卸载wim提交更改,替换服务器使用的启动wim,分发内容并测试它。这是成功的。

作为参考,所需文件列在下面,也在自述文件中。在我的情况下,他们必须来自Windows 8.1 32位安装。如果是64位,则必须来自Windows 8.1 64位的计算机或图像

  • adsldp.dll
  • adsmsext.dll
  • adsnt.dll
  • MSCorEE.dll中
  • mscorier.dll
  • mscories.dll