powershell - Why doesn't Select-String filter the input of a ToString() method?
问题描述
Why doesn't powershell filter the output of an object's toString method?
Get-ChildItem cert:\localmachine\my | % { Select-String -InputObject $_.ToString() -Pattern 'testcert' -SimpleMatch }
Instead I just get everything I would normally get by running
Get-ChildItem cert:\localmachine\my | % { $_.ToString() }
I was expecting that like grep
or findstring
I would get just the lines that match the regex.
One would think that once $_.ToString()
is called, you would just get string output...instead, am I just getting objects, or an array of strings?
解决方案
Select-String
适用于单个字符串...而您只是给它-单个多行字符串。[咧嘴笑]
如果要匹配证书属性中的某个字符串,请使用Where-Object {$_.PropName -match 'TestValue'}
获取包含命名道具中的测试值的对象。
推荐阅读
- azure - 背景噪音 Azure 总线指标中的 Azure AMQP
- google-chrome - 工作箱缓存获取发布请求的数据
- ios - 单元测试找不到 info.plist
- entity-framework-6 - 实体框架插入错误?
- c# - CastleWindsor,在程序集中注册来自公共接口的所有类
- r - 使用因子变量的下拉选择在 Shiny 中编辑数据表
- java - 不能在 getEntityClass 管理器方法中放置实体类
- c++ - 无法理解 libstdc++ 的红黑树迭代器
- pygame - 敌人 AI 碰撞检测不起作用
- amazon-s3 - 有什么方法可以使用预签名的 URL 上传和强制标记?