0

我有一个 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 ADK 中包含的 Windows PE 中运行的。它很可能会像在我的电脑上一样在普通 PC 上正常工作。

需要注意的事项,您需要进行更改以匹配您的环境

  • $域名
  • $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 操作系统版本 6.3.9600.16384

添加的组件

4

1 回答 1

0

Welp .. 找到了我的答案,于 8 月 11 日修复。Reddit 线程

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

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

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

作为参考,下面列出了所需的文件,并且也在自述文件中。就我而言,它们必须来自 Windows 8.1 32 位安装。如果要使用 64 位,它们必须来自具有 Windows 8.1 64 位的计算机或映像

  • adsldp.dll
  • adsmsext.dll
  • adnt.dll
  • mscoree.dll
  • mscorier.dll
  • mscories.dll
于 2014-10-22T23:35:29.303 回答