Dec 112013

Had to write a script to download a few .csv files, cut the first lines (the header) and combine all of them into one big .csv for import into Excel. For various reasons, wrote it in Powershell. First one, so I’m taking note of some basics.

First things first, PowerShell doesn’t execute scripts by default because *security*. Execution-policy has to be set. To see the current value, run:

To set the policy, run

where ‘policy’ is one of:
* Restricted – Scripts won’t run.
* RemoteSigned – Scripts created locally will run, but those downloaded from the Internet will not (unless they are digitally signed by a trusted publisher).
* AllSigned – Scripts will run only if they have been signed by a trusted publisher.
* Unrestricted – Scripts will run regardless of where they have come from and whether they are signed.

In order to read the powershell help, use get-help

Things that make an appearance in this script, in order:

  • ‘do until’ loop. ‘do while’ looks the same, except with ‘while’ instead of ‘until’
  • regex comparison on a string via -match
  • string length, everything is an object in powershell, length is a property
  • asking for user input and saving it into a variable

The files have names like “DDL-20131128.01.001.CSV” (PayPal reports).

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">