Category Archives: Windows

PowerShell – First Script

Here is a script that will read a couple of nodes out of an XML file, then copy the file to a directory build up of the country and date values read out of the file. If the directory is not there, then it creates the directory and then moves the file.

This came up out of the need to automatically file around 40,000 xml files every single day based on their country and date. I think PowerShell was the way to go instead of a batch file because of the xml reading requirement.

# global declarations
$data_rootDir = $(get-location)
# logic
write-host "Iterating xml files in directory " $data_rootDir
$files=get-childitem . *xml|where-object{!($_.psiscontainer)}
foreach ($file in $files){
$xml = [xml](get-content $
# variable declarations
$product_country = $xml.product.productMain.subsidiary
$update_date = $xml.product.productMain.updateTime.substring(0,10)
$data_targetDir = "$data_rootDir\$product_country\$update_date"
write-host "-------------------------------------"
write-host "Moving file $data_targetDir"
write-host `n"Country origin: $product_country"
write-host "Update date: $update_date"
write-host "Target xml directory: $data_targetDir"
# create and move file into daily directory
if(!(test-path $data_targetDir))
"Directory not found, creating..."
new-item -itemtype directory -path $data_targetDir
write-host "Copying file to directory"
copy-item $ $data_targetDir
write-host `n"-------------------------------------"


RDP rdesktop with file integration

Found a cool way to remote from a Linux platform to a Windows platform with a redirect, so that the windows pc can mount the Linux file system.

Using rdesktop from a terminal:

rdesktop -f -k de -r disk:linux=/home/aaron/Downloads/


So, I have just discovered that there are many RDP front-ends for linux that really are just using rdesktop behind the scenes. I like to use KRDC (KDE Remote Desktop Client). I can edit the properties of the connection, add the parameters:

-r disk:linux=/home/aaron/Downloads/

And I get my linux mount point!

Linux Apache to Windows IIS migration with Helicon APE


So I need to migrate a static website from a Linux server to Windows IIS 7. Everything works fine thanks to the static nature of the site, except for one thing – the htaccess security that works under the Apache web server. While its a very simple implementation, making it work the same under IIS has been a little tricky.

Helicon APE (Apache Emulator)

First of all, the company Helicon make 2 products useful for this that we checked out – ISAPI Rewrite 3 and APE. It turns out that APE is what is needed for the security, so keep this in mind when trying things more than just URL re-writing.

Directory Paths

Next trick – if your htaccess files are using directory paths, in my case there are paths to htpasswd & htgroup files, you need to change them from unix style to windows style. Example:





Make sure to include the mapped drive letter at the start of the path if doing absolute references. Hopefully your server’s drive mappings never change letter for any reason :-s haha windows.

Also – dont try to do this manually (opening the file, editing, saving, opening the next one…) if you have more than a couple of files with paths, I use a nifty app called TextCrawler to search and replace text within files and it will find text nested in directories no problem.

Referencing from a secured directory

Apparently when a user hits the index page of this site, they were never asked for a login. There is no htaccess file in the site root directory where the index file is either, so thats what I would expect. But moving all the files just the way they are into IIS, changing the file paths from unix to windows, and nothing else, the user is asked to log in as soon as they hit the index page. If you click cancel, its all good and the user can enter. So why the difference?

Well, the index page is referencing a CSS file which is in a directory that is password protected by an htaccess file. Seems Apache may know the difference but IIS does not (which is fair enough) because this index file is actually referencing resources from a secured directory.

For now I have copied the CSS file into the unprotected root directory and changed the path in the index file to reference this instead. I thought of moving the whole directory, but there are 74 other files with static, relative paths (like …/…/dir/file.css) so that would be a regular expression nightmare at this point to replace all these accurately. For now, once a user gives their user/passwd it appears that they dont need to do it again. So to fix this for the index page I think will be enough for now.

I will keep updating this post as I get closer to winning this migration!

More about the htaccess files:

TextCrawler – Search and Replace Fast

I needed to change 2 lines of text in 54 .htaccess text files all nested in different directories. I found this tool – TextCrawler – and it found all the files and replaced the text in a matter of seconds. Its really easy to use too.