0

I'm trying to gather some statistics using powershell.

I have about 4,000 reports that look like this (all in their own Report.txt files - some have more fields. I've sniped it):

What I would like to do (thinking out loud) is take each [ ] and make that a csv header and then add each item under that header under it. Then I can run simple count statements against it and pull out some data. Maybe there is a better/easier way?

The idea is to have some like:

Requested Permissions: android.permission.INTERNET 3,562 of 4,000 Requested Permissions: android.permission.READ_SMS 1 of 4,000 etc...

So far i've stripped down the string so it no longer has white spaces and *.

[ Package name ]
 * com.software.application

[ Requested Permissions ]
 * android.permission.INTERNET
 * android.permission.READ_PHONE_STATE
 * android.permission.READ_SMS
 * android.permission.RECEIVE_SMS
 * android.permission.SEND_SMS
 * android.permission.WAKE_LOCK
 * android.permission.WRITE_EXTERNAL_STORAGE
 * com.google.android.c2dm.permission.RECEIVE
 * com.software.application.permission.C2D_MESSAGE

[ Responsible API calls for used Permissions ]
 * android/app/NotificationManager;->notify
 * android/content/Context;->sendBroadcast
 * android/content/Context;->startService
 * android/os/PowerManager$WakeLock;->acquire
 * android/os/PowerManager$WakeLock;->release
 * android/telephony/SmsManager;->sendTextMessage

[ Potentially dangerous Calls ]
 * getSystemService
 * HttpPost
 * sendSMS

Current output example:

[PotentiallydangerousCalls]
getSystemService
HttpPost
sendSMS

So it's a bit cleaner now...

2 Answers 2

1

I will put some code if I have time, but here is a roadbook :

1) Write a function (CsvToObject) that take the path and name of a csv file and return a PSObject with a property with each [value]

  • This function can take advantage of switch ... case PowerShell structure with regex and file usage.

2) Take every *.csv file (Get-ChildItem) , call your function and pipe the result in Export-CSV

Sign up to request clarification or add additional context in comments.

Comments

0

Your current output example is structured like an ini file. This Scripting Guy post on ini files might be useful. Some regex help here and here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.