2015-12-17 27 views
0

使用下面的脚本我试图过滤掉没有像Windows 10那样的$需求的应用程序。当我运行这个时,我仍然得到包含Windows 10的应用程序需求的返回结果。Where子句没有正确过滤

| Where { $_ -notlike 'All_x64_Windows_10_and_higher_Clients' }; 

任何想法我在做什么错在这里?上面这行可能存在问题?

$warningpreference = "SilentlyContinue" 
Get-Content C:\temp\Applications.txt | foreach-object { 
$app = Get-CMApplication -Name "$_"; 
[XML]$appXML =$app.SDMPackageXML; 
$Requirement = $appXML.AppMgmtDigest.DeploymentType.Requirements.Rule.OperatingSystemExpression.Operands.RuleExpression.RuleID | Where { $_ -notlike 'All_x64_Windows_10_and_higher_Clients' }; 
If ($Requirement -ne $null -or $Requirement.length -gt 0) { 

Write-output "Application Name: $_ | Requirement: $Requirement " 
} 
} 
+1

好了,怎么办属性值的样子,你想过滤掉?你在那里的条件和使用'-ne'...''一样,所以我想你想用'-notlike'出于某种原因,但是无法得到正确的模式。 – Joey

+0

我想只返回他们没有Windows10需求的应用程序。好像任何过滤我做的是不工作 – user1342164

回答

1

类似运算符用于PowerShell中的WildCard搜索。所以你需要一个*在你的过滤器的某个地方。

试试这个:

| Where { $_ -notlike "*All_x64_Windows_10_and_higher_Clients*" }; 
+0

谢谢我试过这个,它只是从输出中取出All_x64_Windows_10_and_higher_Clients,并仍然显示具有此要求的应用程序 – user1342164

+0

然后你究竟在做什么?您的命令行表示删除客户端,如“* All_x64_Windows_10_and_higher_Clients *” – FoxDeploy