首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell FindAll() ComException

Powershell FindAll() ComException
EN

Stack Overflow用户
提问于 2014-08-04 16:35:30
回答 1查看 3.1K关注 0票数 0

我有一个powershell脚本,我们在Microsoft任务序列中使用它来命名PC。它完美无缺地工作,直到最近由主服务器管理员升级到SCCM2012 R2。

现在,当代码运行搜索时,如果用户在完成PXE生成所需的指定AD组中,则会出现以下COM错误

代码语言:javascript
复制
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错误,但我没有成功地解决它。

下面是相关代码。注意,这是在SCCM2012 R2以及当前Windows中包含的Windows中运行的。它很可能在普通PC上正常工作,就像在我的电脑上一样。

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

  • $Domain
  • $strFilter --特别是"Memberof=cn=“
  • $objOU -服务器路径
代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-22 23:35:29

欢迎..。找到我的答案了,修好了8月11日。Reddit线程

在2012年的SCCM中,在R2之前,引导映像是一个Windows8 PE4映像,在这个映像中,我们必须将ADSI集成到使用约翰·阿维马克编写的版本中。这可以找到这里作为参考。

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

最后,我用DISM手动将wim文件挂载到我的PC上,从一个文件夹中添加了驱动程序,允许安装未签名的文件。然后在挂载的System32文件夹中手动验证dll的位置。完成之后,我能够卸载wim提交的更改,替换服务器使用的引导wim,分发内容并测试它。这很成功。

作为参考,所需的文件列在下面,也在自述文件中。在我的例子中,它们必须来自Windows8.1 32位的安装。如果想要64位,它们必须来自带有Windows8.1 64位的计算机或图像

  • adsldp.dll
  • adsmsext.dll
  • adsnt.dll
  • mscoree.dll
  • mscorier.dll
  • mscories.dll
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25123421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档