I was using the brail view engine yesterday and ran into a problem. So I wanted to be able to find all the places I was calling ToString( ) on a variable and passing in a format. Powershell makes this nice and easy.
So here's what happens.
gci is an alias for get-childitem (you can also use dir or ls)
I tell it i want to recurse and only check files with the .brail file extension.
Next I pipe ( | ) the output to the select-string commandlet which will find all matches in each file.
The output of select-string looks something like this
Ebp\Statement\DownloadUsageDetails.brail:3:${item.OccurredOn.ToString("d")},${item.OccurredO
n.ToString("T")},${item.FromPlace},${item.FromState},${item.ToPlace},${item.ToState},${item.
MinuteTenths},${item.Amount.ToString("c")
Ebp\Statement\viewsummary.brail:99: <dd class="Charge"><strong>${total.ToStri
ng("c")}</strong></dd>
But this is not that useful for what I'm trying to do, so I run this command:
Which yields something a bit more useful:
IgnoreCase : True
LineNumber : 3
Line : ${item.OccurredOn.ToString("d")},${item.OccurredOn.ToString("T")},${item.FromPl
ace},${item.FromState},${item.ToPlace},${item.ToState},${item.MinuteTenths},${i
tem.Amount.ToString("c")
Filename : DownloadUsageDetails.brail
Path : C:\develop\ecrm\source\Martin.eCRM.Web\Views\Ebp\Statement\DownloadUsageDetails
.brail
Pattern : ToString
IgnoreCase : True
LineNumber : 99
Line : <dd class="Charge"><strong>${total.ToString("c")}</strong></dd>
Filename : viewsummary.brail
Path : C:\develop\ecrm\source\Martin.eCRM.Web\Views\Ebp\Statement\viewsummary.brail
Pattern : ToString
However I have a lot of files so in reality this list is much longer, but what Format-List told me was that the output of select-string created objects with a FileName property so I change my command to be:
Which gave me this nice output:
Count Name Group
----- ---- -----
1 DownloadUsageDetails.b... {DownloadUsageDetails.brail}
1 viewsummary.brail {viewsummary.brail}
3 _usagedetailstable.brail {_usagedetailstable.brail, _usagedetailstable.brail, _usa...
8 index.brail {index.brail, index.brail, index.brail, index.brail, inde...
3 paymenthistory.brail {paymenthistory.brail, paymenthistory.brail, paymenthisto...
1 EditPackage.brail {EditPackage.brail}
1 ListFeatures.brail {ListFeatures.brail}
4 OrderSummary.brail {OrderSummary.brail, OrderSummary.brail, OrderSummary.bra...
And now I can look at which files need editing and how many occurrences there are.
Enjoy