我想通过WMI获取所有SCCM Tasksequnece,并将它们与图像名称匹配
$TaskSequence = Get-WmiObject -Namespace "root\SMS\site_$($SiteCode)" -Class SMS_TaskSequencePackage -ComputerName $SiteServer
$ImagePackage = Get-WmiObject -Namespace "root\SMS\site_$($SiteCode)" -Class SMS_ImagePackage -ComputerName $SiteServer
$TaskSequence.name
的输出
Windows Server 2012 R2 X64
Windows 10 Enterprise x64 USMT完整操作系统
升级1703
Windows 10 Enterprise x64 USMT硬链接
Windows 7 Enterprise x64 zh-CN Windows 10 Enterprise x64 1703 zh-CN Windows Server 2016
$ImagePackage.name
的输出
Windows Server 2016 x64
Windows 10 Enterprise x64
我试过这个foreach循环,但似乎无法让它工作,这篇文章提示,应该只有4个提示,3个Windows 10和1个Windows服务器2016
foreach ($TS in $TaskSequence ) {
Get-WmiObject -Namespace "root\SMS\site_$($SiteCode)" -Class SMS_TaskSequencePackage -ComputerName $SiteServer |
ForEach-Object{
Get-WmiObject SMS_ImagePackage -Namespace "root\SMS\site_$($SiteCode)" -ComputerName $SiteServer | Where-Object { $_.name -like "*$($TS.Name)*"}
}
}
答案 0 :(得分:0)
修改强> 问题改变之后,这里有一个新代码:
$SiteCode = "SiteCode"
$SiteServer = "Server"
$TaskSequence = (Get-WmiObject -Namespace "root\SMS\site_$($SiteCode)" -Class SMS_TaskSequencePackage -ComputerName $SiteServer)
$ImagePackage = (Get-WmiObject -Namespace "root\SMS\site_$($SiteCode)" -Class SMS_ImagePackage -ComputerName $SiteServer)
Foreach($Task in $TaskSequence){
foreach($Image in $ImagePackage){
if($Task.Name -like "*$($Image.Name)*" -or $Image.Name -like "*$($Task.Name)*"){
$Task
#I have no idea what you want to do with this object
}
}
}