new to powershell and i'm kind of stuck.
I would like to get all SCCM Tasksequnece with WMI, and match them with the image name
$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
Windows Server 2012 R2 X64
Windows 10 Enterprise x64 USMT Full OS
Upgrade 1703
Windows 10 Enterprise x64 USMT Hardlinks
Windows 7 Enterprise x64 en-US
Windows 10 Enterprise x64 1703 en-US
Windows Server 2016Output of
$ImagePackage.name
is
Windows Server 2016 x64
Windows 10 Enterprise 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 ($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
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.