Author

I am Joannes Vermorel, founder at Lokad. I am also an engineer from the Corps des Mines who initially graduated from the ENS.

I have been passionate about computer science, software matters and data mining for almost two decades. (RSS - ATOM)

Meta

Entries in powershell (4)

Wednesday
Oct312007

Crypt your config files with PowerShell 

ASP.Net 2.0 comes with a convenient native support for configuration file encryption. Yet, things are still not that easy for WinForms, Console applications or Windows Services since the aspnet_regiis.exe utility only supports Web Configuration files.

My own μISV has its share of distributed applications which involve securing a few connection strings over several machines. Securing the connection strings through encryption is not an ultimate defense (if the attacker gains executions rights on the local machine, connection strings will get disclosed anyway), but it can still save you a lot of trouble such as involuntary disclosure.

Download crypt-config.zip

I have found a practical way to solve the issue through PowerShell (see the PowerShell team blog for regular tips), namely two functions crypt-config and decrypt-config. The source code comes as single PSH script contains the function definitions.

To get started, extract the PS1 file from the Zip archive, then

PS docs:\> . ($directory + "\crypt-config.ps1") ;

PS docs:\>crypt-config 'MyConsole.exe' 'section';

PS docs:\>decrypt-config 'MyConsole.exe' 'section';

Typically, section will be replaced by connectionStrings. Note that you do not need to add the .config at the end of the configuration file path.

Sunday
Mar182007

Format-Graph CmdLet; Drawing graphics with PowerShell

PowerShell, through its object-oriented design, provides a flexible and powerful framework to build interactive shell commands. Lately, in order to produce quick&dirty graphs while working on Lokad, I came up with Format-Graph, a CmdLet that outputs a text-based graphics of curves extracted directly from the PowerShell pipeline.

Format-Graph screenshot

For those who might be interested, the source-code of the Format-Graph CmdLet is freely available as a part of the Lokad OpenShell project. The class is stand-alone, you not need the rest of the Lokad OpenShell project to get it working.

The key idea behind the Format-Graph is the way to actually retrieve, from the pipeline, the values to be plotted. Indeed, if the Format-Graph was relying on some arbitrary strong-typed inputs (think of a class named Point); then this CmdLet would be pretty much useless. Indeed, using the Format-Graph would require some heavy input formatting to actually produce anything. Instead, Format-Graph leverages the .Net reflexion to extract the values from the pipeline.

Basically, Format-Graph takes a ValuePropertyName argument that is used to extract the actual double value from the specified property. For example, in the screenshot here above, I have used -ValuePropertyName:Value to extract the values from TimeValue objects.

Future development notes: Format-Graph does not provides any axis description for now. I have already included a LabelPropertyName argument as a placeholder (labels are just ignored for now); but I am unsure about the way to handle the X axis description at this point. Additionally, I am considering to (optionally) display some scaling information for the Y axis.

Saturday
Feb102007

FTP upload to Sourceforge with PowerShell

The release system of Sourceforge.net requires to upload your files by FTP to upload.sourceforge.net. The process is basically a pure pain, especially for small files:

  • sourceforge.net is slow, upload.sourceforge.net is slow too.

  • you need to process your files by FTP whereas it could have been done much more easily through a simple web upload (at least for file that are less then 5MB which must account for 99% of the file released on sourceforge anyway).

  • if you want to re-upload your file, then you cant do it by FTP; you need to go through the SF.net web UI: first release the uploaded file, then delete the released file and finally re-upload your file (the process is maddening).

Anyway, here below is a PowerShell script that I am using to upload files by FTP to sourceforge.net. Save this script into ftp2sf.ps1, then from the PowerShell command-line, just type .\ftp2sf.ps1 'myPackage.zip' and your file will get upload to sourceforge.net. Then, go through the sourceforge release interface and complete the process.

# ftp2sf.ps1 - FTP UPLOAD TO UPLOAD.SOURCEFORGE.NET
#
# Author: Joannès Vermorel
# http://www.vermorel.com/
#
# USAGE:
# .\ftp2sf.ps1 'myLocaFile'

Param( $UploadFilePath = "filename" );

$FtpUploadCommand = "PUT `"" + $UploadFilePath + "`"";

$FtpCommandFilePath = [System.IO.Path]::GetFullPath("FTPCommand.tmp");

$FtpCommands = @( "anonymous", "myemail@example.com", "cd incoming" , "bin", "quote pasv", $FtpUploadCommand, "quit" );

$FtpCommand = [String]::Join( "`r`n", $FtpCommands );

set-content $FtpCommandFilePath $FtpCommand;

ftp "-s:$FtpCommandFilePath" upload.sourceforge.net;

remove-item $FtpCommandFilePath;

Wednesday
Nov082006

A small developer-oriented PowerShell wish list

I have just started to use the PowerShell a few days ago; and I am more and more impressed by the work that have been done by the MS folks. Yet, being a developer, I have the feeling that many aspects of PowerShell still need to be polished.

  • Too bad that there is no Visual Studio project templates for CmdLets. Providing an hello-world CmdLet with its associated SnapIn would really make the life of the developers easier, smoothing the learning curve.

  • Implementing a CmdLet is so full of traps, I would really see some strong FxCop support to help the poor developers to avoid the most obvious errors.

  • A few objects dedicated to CmdLet unit testing. Currently, in order to get a CmdLet unit tested, you have to resort to some custom tricks. A small dedicated & embedded testing framework would ensure that the CmdLet environment is simulated in a proper manner.

  • A dedicated MSBuild task to include whole PowerShell scripts (using the CDATA); the MSBuild properties being inherited as PowerShell variables. MSBuild and PowerShell do have very complementary design; integration would be the key to leverage both of them.

  • Some XSLT convertion to transform the .Net documentation produced by the compiler into CmdLet Help documentation. In the current situation, the CmdLet documentation end-up duplicated in the .Net source and in the CmdLet XML documentation file.