![如果列與 Powershell 中的 CSV 部分或完全匹配,則傳回一行](https://rvso.com/image/1615242/%E5%A6%82%E6%9E%9C%E5%88%97%E8%88%87%20Powershell%20%E4%B8%AD%E7%9A%84%20CSV%20%E9%83%A8%E5%88%86%E6%88%96%E5%AE%8C%E5%85%A8%E5%8C%B9%E9%85%8D%EF%BC%8C%E5%89%87%E5%82%B3%E5%9B%9E%E4%B8%80%E8%A1%8C.png)
基本上,我想搜尋一個字串並以 CSV 格式傳回任何完整或部分匹配項。
假設我有一個$Shoes
看起來像這樣的物件:
"Brand","Style","Color","Price"
"Reebok","Basketball","Red/Black","$50"
"Vans","Slip-On","White/Black","$60"
"Vans","Old Skool","Red/White","$60"
"Nike","Sneakers","Red","$50"
"Adidas","Sneakers","Blue","$55"
為了使其更具可讀性,格式化為表格如下:
Brand Style Color Price
----- ----- ----- -----
Reebok Basketball Red/Black $50
Vans Slip-On White/Black $60
Vans Old Skool Red/White $60
Nike Sneakers Red $50
Adidas Sneakers Blue $55
鍵入$Shoes -like '*Red*'
返回:
@{Brand=Reebok; Style=Basketball; Color=Red/Black; Price=$50}
@{Brand=Vans; Style=Old Skool; Color=Red/White; Price=$60}
@{Brand=Nike; Style=Sneakers; Color=Red; Price=$50}
但我正在尋找的輸出是:
Brand Style Color Price
----- ----- ----- -----
Reebok Basketball Red/Black $50
Vans Old Skool Red/White $60
Nike Sneakers Red $50
我在這裡做錯了什麼?
答案1
我想當我嘗試時我格式 -match 不正確,結果是簡單的解決方案...
這簡直就是$Shoes -match 'Red'