Execution of external commands (native applications) in PowerShell done right – Part 3

Part 1, Part 2 Hi folks I realized that my previous implementation has a flaw. I though that exit code always 0..255 but this is the case only in DOS. In Windows it can be any signed 32-bit integer. So I had to fix it. You cannot create an array with all int values in […]

Get EXIF metadata with PowerShell

Hi folks Sometimes we need to extract some exif data from images. We could do this with PowerShell. Here is the most efficient way to do this PSUsing was described in the previous blogpost Here is the list of tags: http://www.digitalpreservation.gov/formats/content/tiff_tags.shtml For example, date taken tag is http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/datetimeoriginal.html Date in the following format: “yyyy:MM:dd HH:mm:ss” […]

Execution of external commands in PowerShell done right

Part 2 Part 3 Hi folks Execution external (native) commands in PowerShell is not an easy thing. It looks like it is simple but it has a lot of downsides. We’ll consider the following command And use it like that It writes a message to STDOUT, a message to STDERR and returns some exit code. […]

PowerShell auto variable $LastResult

Hi folks If you work a lot with PowerShell you may had the cases when you tried something and then you want to save it to the variable. Many REPLs has a concept of last result variable but not PowerShell, unfortunately. Here are some resource that I’ve used http://stackoverflow.com/questions/14351018/powershell-is-there-an-automatic-variable-for-the-last-execution-result http://dmitrysotnikov.files.wordpress.com/2011/09/scripts-tec-2011-jeffrey-snover-proxy-functions.pdf http://get-powershell.com/post/2008/06/25/Stuffing-the-output-of-the-last-command-into-an-automatic-variable.aspx http://poshcode.org/803 But all these […]

sqlcmd – Get real sql error line number

Hi folks Consider the following sql script When you run with SQLCMD When you run in SQL Server Management Studio with SQLCMD Mode enabled you get But when you double click on the error line the query editor will jump to the problematic line. Reported Line 2 means a line number relative to the batch. […]

PowerShell $ErrorActionPreference = “Stop” vs error tracing

Hi folks For a long time I noticed that sometime my failing scripts don’t report error line correctly and recently I’ve managed to narrow down the issue Consider the following script When we run it we get As you see it reports the problem in line #18 Line 18: But the actual problem is in […]

PowerShell Start-Process WTF

Hi folks Another WTF… Let’s try And it returned nothing. As I described in the previous blogpost, this means that some exception occurred returns That is a known PowerShell bug: Start-Process: http://connect.microsoft.com/PowerShell/feedback/details/585549/start-process-passthru-return-value and http://connect.microsoft.com/PowerShell/feedback/details/520554/start-process-does-not-return-exitcode-property And here is the workaround returns 123