我正在寻找帮助,使我的方法更加高效,因为我的方法真的很愚蠢但有效
我在stackoverflow上搜索了一下,但没有找到符合我想法的东西
ForEach($app in $apps){
ForEach($removeapp in $applist)
{
If ($app.Displayname -like $removeapp.appname) {
Write-Host "Removing: " $app.Displayname -ForegroundColor Green
}
Else{
Write-Host "Skiping: " $app.Displayname -ForegroundColor Red
}
}
}
我基本上比较了他们中的每一个是什么给了我x ^ y possibillitys什么是非常糟糕的并且让它减慢任何帮助如何更快地做到这一点?
$apps
包含图像中的每个配置应用程序包
例如 - > Displayname = Microsoft.ZuneMusic
$applist
包含那些以CSV格式删除shell的应用程序 - > Appname = Microsoft.ZuneVideo
我想清楚地看到哪些被删除,哪些被删除。
我想我会使用正则表达式-match
运算符。如下所示:
# build a regex from all the app displaynames joined using the regex OR ("|") character
$appNames = ($apps | ForEach-Object { [regex]::Escape($_.DisplayName) }) -join '|'
$applist | ForEach-Object {
if ( $_.appname -match $appNames ) {
Write-Host "Removing: $($_.appname)" -ForegroundColor Green
}
else {
Write-Host "Skipping: $($_.appname)" -ForegroundColor Red
}
}
希望有所帮助