简体   繁体   English

Powershell Match使用Like Wildcard从2个容器输入的内容

[英]Powershell Match input from 2 containers with Like Wildcard

new to powershell and i'm kind of stuck. Powershell的新手,我有点被卡住了。

I would like to get all SCCM Tasksequnece with WMI, and match them with the image name 我想使用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

Output of $TaskSequence.name is $TaskSequence.name输出为

Windows Server 2012 R2 X64 Windows Server 2012 R2 X64
Windows 10 Enterprise x64 USMT Full OS Windows 10企业版x64 USMT完整操作系统
Upgrade 1703 升级1703
Windows 10 Enterprise x64 USMT Hardlinks Windows 10企业版x64 USMT硬链接
Windows 7 Enterprise x64 en-US Windows 7企业版x64 zh-CN
Windows 10 Enterprise x64 1703 en-US Windows 10 Enterprise x64 1703 zh-CN
Windows Server 2016 Windows Server 2016

Output of $ImagePackage.name is $ImagePackage.name输出是
Windows Server 2016 x64 Windows Server 2016 x64
Windows 10 Enterprise x64 Windows 10企业版x64

I tried with this foreach loop, but cant seem to get it working, this post 7 hints, there should only be 4 hints, 3 Windows 10, and 1 Windows server 2016 我尝试使用此foreach循环,但似乎无法正常工作,本文有7条提示,应该只有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)*"} 
    }

}

EDIT: After the question changed a little here is the new code: 编辑:问题稍作更改后,这里是新代码:

$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
        } 
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM