Build Instructions for the DIY Cat Feeder

A few weeks ago, Design News ran an engineering-centric article on the DIY Cat Feeder that entertained my cats while I was on vacation last year. Everybody loves a good hack, but I’ve been surprised by the attention it received. If you’ve been wanting to know more about how it was built, the article provides much more detail.

As part of their article preparation, they asked for mechanical and schematic …

Read more

Interacting with SQL Databases in PowerShell: Invoke-SqlCommand

Jeffrey McManus recently wrote about database queries with PowerShell – a small script that lets you query a SQL data store. This is really powerful. Rather than context switch into SQL Express (or TOAD, or your other favourite administration tool,) you can do what you need from PowerShell.

It goes even further, though. A lot of PowerShell’s built-in commands have a set-oriented flavour: Where-Object, …

Read more

Managing INI files with PowerShell

The question came up on the newsgroup a few days ago on how to work with INI files from PowerShell.

A lot of great answers came up (using text parsing of the INI files,) but the Windows API actually supports reading and writing of INI file entries directly through its GetPrivateProfileString and WritePrivateProfileString functions. PowerShell doesn’t support P/Invoke to the Win32 API directly, but the Invoke-Win32 …

Read more

Using PowerShell and PsExec to invoke expressions on remote computers

While eagerly awaiting PowerShell’s upcoming remoting functionality, many people turn to Sysinternals’ PsExec tool to build their own version. However, PowerShell seems to hang when called via PsExec on the remote machine. This has come up on the SysInternal forum (http://forum.sysinternals.com/forum_posts.asp?TID=10823) among other places, and is caused by the same issue outlined here: …

Read more

Removing Certificates from the Certificate Store

This has come up twice in as many days… how do you remove certificates from the certificate store in PowerShell?

The certificate provider is ultimately a read-only view of your certificates. It does help you retrieve certificates, however, which is an important step in ultimately removing one from a store.
 
To remove one, you’ll need to use the .NET APIs:

[cert:\CurrentUser\TrustedPublisher]
PS:200 > dir …
Read more

Cmdlets vs Functions

A discussion came up recently in an internal mailing list about the difference between Cmdlets and Functions. What was most interesting was how many hard and fast distinctions and rules came out of the discussion, even though those distinctions don’t really exist.

The key point is that there really isn’t a hard and fast philosophical distinction between cmdlets and functions.

Most differences largely exist because of …

Read more

Secret SQL Escape Characters

I learned of an evil SQL escape sequence today, in the context of a data migration script. The script moves data from one database to another, but the schema changes between databases, so you can’t use BCP. As such, the script needs to ensure that it does not modify any of the database content.

The script works well, and it creates insert statements based on the values and the content of the old data. In the …

Read more

Invoking Generic Methods on Non-Generic Classes in PowerShell

A question recently came in asking, “How do you invoke a generic method on a non-generic class in PowerShell?”

[Edit: this "just works" in PowerShell V3]

PS C:\Users\Lee> Add-Type -Path C:\temp\generic.cs
PS C:\Users\Lee> $r = New-Object NonGenericClass
PS C:\Users\Lee> $r.GenericMethod("Hello", "Hello")
Hello Multi Generic World: True

In an earlier post ( …

Read more

Obfuscated PowerShell

For some reason, a surprisingly common (albeit half-joking) remark about PowerShell is that it hasn’t “arrived” until you can write obfuscated one-liners like you do in C or Perl. They may have missed Adam’s obfuscated script (http://www.proudlyserving.com/archives/2005/11/obfuscated_mona.html,) or this email quoting / wrapping one-liner: …

Read more

Why Another 3rd Party Book?

Gerd recently posed a good question on the PowerShell blog:

_I’m really surprised to read about another 3rd party book from a member of the PS team. To me PS is the most intriguing MS innovation for years and Bruce’s book is really excellent and answered almost all my questions, but maybe I’m not the only one wondering why PS team members write that busy for the bookstore shelf, as long as the …

Read more