Powershell Like Wildcard issue

BenDK

Can't get this wildcard comparison to work, what am I doing wrong? I can only get:

Windows Server 2016

Windows 10 Enterprise x64

For instance, I can't get

Windows 10 Enterprise X64 1709 ?

how come? I also get only 2 hints, it should give me 5

Output of $TaskSequence.name is

Windows Server 2012 R2 X64

Windows 10 Enterprise x64 USMT Hardlinks

Windows 10 Enterprise x64 1703 en-US

Windows Server 2016

Windows 10 Enterprise x64 USMT Full OS

Windows 10 Enterprise x64

Windows 7

Output of $ImagePackage.name is

Windows Server 2016 x64

Windows 10 Enterprise x64

$SiteCode = "PS1"
    $SiteServer = "SRVSCCM01"
    $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.name

            } 
        }
    }
BenDK

i'm really studpid, sometimes you just need to look at your code from another angle, i was doing a

Get-WmiObject -Namespace "root\SMS\site_$($SiteCode)" -Class SMS_TaskSequencePackage -ComputerName $SiteServer| where-object {$_.Name -like "*$($Task.Name)*"   }

inside the foreach loop, which defeats the purpose, so i just added another foreach, and now it all works perfectly as intended - thanks for all your sugestions

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related