Posts

PowerShell: which for windows

As Stephen Mills points out in a comment below, all this is unnecessary because there's a cmdlet that does this even better. Get-Command So please disregard this post :P Fresh code out of the oven. I was on my Windows XP box and needed to know where I had an specific executable file stored. Some Windows boxes have a similar command called where but it wasn't availed in my box. So I just coded one in PowerShell. function which ($file){ $return = @() if (Test-Path ".\$file" -ea silentlycontinue){ # check current dir $return +=@(".\$file") } foreach ($path in (get-content env:path).Split(";")){ # check all paths in PATH env var if (Test-Path "$path\$file" -ea silentlycontinue){ $return += @("$path\$file") } } return $return } Off course it can be refined - and probably should - but it's good enough for most situations. Ex: > which notepad.exe C:\WINDOWS\system32\notepad.exe C:\WINDOWS\notepad.exe PS: I store...

PowerShell: very simple FTP client

One of my first experiments with PowerShell, besides ls and HelloWorld.ps1, was trying the object oriented features and the .Net Framework. I was at the time thinking about a problem I was having with an FTP client I was using and I asked myself: "Would it be possible to make an FTP client with PowerShell?" I knew there was a .Net class that implemented an FTP client so I googled and bit and found it . After reading the examples shown and a little try-and-error, I came up with this extremely simple FTP client in PowerShell below. Note that by "extremely simple" I mean "with very few features and no error detection code". This only gets one file from the FTP server. I probably wouldn't use this in production without a few changes. But it's still a nice example on how to use the .Net framework with PowerShell and this class in particular $localfile = "c:\file.txt" $remotefile = "/folder/file.txt" $ftphost = "ftp://ftpserver...

PowerShell

A few weeks ago I had a chance to attend a workshop about PowerShell entitled "Using PowerShell" by Ed Wilson . Fantastic teacher and fantastic person to talk to about anything. This was my first time using PowerShell. I had tried one of Monad's first versions but it took so much time to load and crashed so many times I decided to wait for a final version. I ended waiting a bit more than the final version though. My first impression was "This is fantastic!! ". And it really is. Being a lover of the command line and an avid user of Bash and other UNIX shells, I welcome PowerShell. I'm not going to compare Bash and PowerShell and try to guess the best shell. In my humble opinion, they're not comparable. For that kind of entertainment, google for PowerShell vs Bash. You'll probably get a lot of results with links to endless and pointless discussions between UNIX and Windows zealots. PowerShell and Bash have very few similarities. Quoting Ed Wilson ...

Missing Win32_Product

Today I spent some frustrating time debugging a VBScript looking for an authentication problem that didn't exist. I was trying to a install an MSI file on a remote server and kept getting "SWbemServicesEx: A security package specific error occurred." Googling the error only drove me further in the wrong way. Only when I decided to run the script locally on the target computer I realised it wasn't an authentication problem. At least not any more. The error was now "SWbemServicesEx: Not found". I then noticed the Win32_Product class I was using to install the MSI files did not exist. I googled for the error and found lots of people with the same problem but no straightforward solution. Well... it turns out this was not the first time this happened to me... Maybe the next time this happens I google it and find my own blog post with the answer. It's as simple as this: "Add/Remove Programs" "Add/Remove Windows Components" "Management...

Citing Wikipedia

I love the Wikipedia . It's a great place to search for any kind of information and a good place to start learning about anything. Is it trustworthy enough so you can cite it in scientific projects? Well... that's arguable and has been arguable since it was created. But arguments I have read aren't always good enough for one side or the other. Even though anyone can edit it and insert incorrections, the articles are quickly corrected by maintainers and visitors. I've seen this happen in real time while I was browsing the wikipedia. Off course this depends on the article itself and the attention it gets from other users. What if when we last read it and acquired information it was wrong and only corrected after we closed the browser? In my opinion it's up to the reader to cross check the information before using it in an important project. But this is also true for most scientific papers. This is one of those views , against citing the Wikipedia, that misses the poi...

Samsung CLP-300

I just bought a colour laser printer from Samsung. The CLP-300. Why the CLP-300? Most of my prints are text documents. From scientific papers to music tablatures and, off course, "how to" articles. I rarely print photos... and I definitely didn't want to buy a relatively good photo printer for a reasonable price and then spend the value of the printer per month in ink cartridges. I might be exaggerating a bit here but you get the idea. Laser printers are usually cheaper per print and therefore a cheap monochromatic laser printer seemed to be a good choice for me. I only had one more problem to solve. I live with my girlfriend and she would be using the printer too. The problem is she loves colours. My plan is ruined... or is it? I started looking for colour laser printers but most of them were very expensive. Much more than the monochromatic models. Enter the CLP-300. It's a small sized (at least for a laser printer), it's low priced and it's relativ...

Another Mac OS X installation bites de dust...

This time it was scary... and I'm still scarred because I'm not sure what happened and if it will happen again. I hope it's not a hard-drive problem but it sure looked like it even thou the Disk Utility didn't report any problem. I had shut down the laptop for a while and when I came back, it didn't start. There was no rEFit menu as the MacBook seemed to go directly to Mac OS X. But Mac OS X wouldn't start either. I would get to this screen where a progress bar appears but the progress bar kept returning to zero and start all over again. I then booted using an Ubuntu Live CD holding the "c" key at start up. It booted fine and all my data seemed ok. So I backed up all of it to another computer. Again, Linux saved my day. I then tried to reinstall over the current partition but no go. The installation utility kept telling me some error occurred trying to install and advising me to try again. The only way I found to install OSX was by removing all existe...