Using C# in PowerShell to move files


Screedump form Windows PowerShell ISE





$source = @"

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Rvl.Demo.Common
    public class MoveFiles
        public static void Move()
            string sourceFolder = @"C:\BDATA\Test\Source"; // Source folder
            string destinationFolder = @"C:\BDATA\Test\Destination"; // Destination folder
            DateTime checkDateTime = new DateTime(2010, 12, 29, 13, 0, 0); // 27-dec-2010 13:00:00
            // Loop all files in source folder
            foreach (string file in Directory.GetFiles(sourceFolder))
                // Calculate difference between checkDateTime and file last modified datetime in days
                DateTime fileLastModifiedDate = File.GetLastWriteTime(file);

                // Move files if difference in days == 0
                if (checkDateTime.Year == fileLastModifiedDate.Year && checkDateTime.Month == fileLastModifiedDate.Month && checkDateTime.Day == fileLastModifiedDate.Day)
                    string destinationFilePath = Path.Combine(destinationFolder, Path.GetFileName(file));
                    Console.WriteLine(string.Format("Moving file [{0}] to [{1}]", file, destinationFilePath));

                    File.Move(file, destinationFilePath);

Add-Type -TypeDefinition $source


How to enable logging for Dts.Log statements in a SSIS Script Task

If you want to log from a script task, you can use the Dts.Log function.

This function can log to the system table: dbo.sysssislog. If you configure you’re package logging correctly.



Most importantly, if you want to log from a script task by using the function Dts.Log, enable logging for the specific script task and enable "ScriptTaskLogEntry"


Steps to enable logging from within you SSIS script task
Make sure you’re Script Task contains a Dts.Log function call, like:

public void Main() { // Define log message string message = "This is my log text"; // Log the message Dts.Log(message, 999, null); Dts.TaskResult = (int)ScriptResults.Success; }

In the control flow right click and choose Logging…

Check all checkboxes in the treeview, make sure the script task is not grayed out or unchecked

Click on the top node in the treeview and add SSIS log provider for SQL Server:


Enable ScriptTaskLogEntry in the details tab of the script task


When you run this package, you should see the logging in the table dbo.sysssislog

Using XBMC on my ASUS EEE Box 1012P


Because the ASUS EEE Box 1012P is shipped with Windows 7, I first installed XBMC 10.0 (released 19-dec-1010). on Windows 7.


– Download XBMC 10.0 from

– Next Next Finish installation.


Network Share

– Create a network share, so all sources in the XBMC database will be pointed to the network share. This ensures you are able to use a shared MySQL database on all XBMC installations in you’re house.

– Created the following folders on the network share

  • Internet Radio (pls files)
  • Movie (Cinema movies)
  • Music (Constains a folder per album with the name Artist – Albumname)
  • Pictures (Contains all pictures)
  • Videos (contains home video’s)



XBMC > Settings


Setting Value
Add-Ons > Album information AllMusic
Add-Ons > Album information Last.FM
Add-Ons > Artist information AllMusic
Add-Ons > Artist information Last.FM
Add-Ons > Movie information IMDb
Add-Ons > Movie information Moviemeter
Add-Ons > Program Add-Ons XBMC Library Auto Update
Add-Ons > Skins Transparency!
Add-Ons > Subtitles XBMC Subtitles
Add-Ons > TV information The TVDB
Appearance > Skin Transparency!
Appearance > International > Region Central Europe
Appearance > File lists Allow file renaming and deletion
Appearance > Screensaver Use visualization if playing audio [Disable]
Music > Library Download additional information during updates
Music > Library Update library on startup
Music > Playback > Visualization None
Music > Audio CDS Play adio CDs automatically
Music > Audio CDS > Bitrate 320 kbs
Network > Services Share video and music libraries through UPnP
Network > Services Allow control of XBMC via UPnP
Network > Services Allow control of XBMC via HTTP
Network > Services Allow programs on other systems to control XBMC
Pictures > File Lists Show video files in listings
Pictures > Slideshow Disable "Use pan and zoom effects"
Skin Settings > General Enable auto scrolling for plot & review
Skin Settings > General Movies – Use extra fanart
Skin Settings > General Movies – Use extra thumbs
Skin Settings > General TV shows – Use posters
Skin Settings > General TV shows – Use extra fanart
Skin Settings > General Music – Use extra fanart
Skin Settings > General Show fanart slideshow instead of visualization
– Disable pan and zoom effects
Skin Settings > General Enable touchscreen modus
Skin Settings > Scripts Show subtitle script button in OSD
Select script: XBMC Subtitles
Skin Settings > Menu Favorites
System > Audio Ouput > Audio output Optical/Coax
System > Audio Ouput > Speaker Configuration 5.1
System > Audio Ouput > Audio output device default
System > Input devices Remote control sends keyboard presses
System > Video output Fullscreen
System > Power Saving Shutdown function: Suspend
Video > DVDs Play DVDs automatically
Video > DVDs Attempt to skip introduction before DVD menu
Weather Breda
Bergen op Zoom
De Bilt





Overwriting the msiexec property TARGETDIR for x86 and x64 application setups

If you want to remove a application from you’re system you can use:

msiexec /x {product_guid}
like: msiexec /x {2EAB2958-5675-4773-9BF6-2C8FB9DF9CC6}


If you want to install a *.msi package, but want don’t want to install the application to the default installation folder you can overwrite the TARGETDIR property, like

msiexec /i "C:\Temp\MyFirstApp.msi" TARGETDIR="D:\Programs\MyFirstApp"

But if you’re msi package is created with Microsoft Visual Studio and the property Targetplatform of the setup project is set to x86, you can’t overwrite the TARGETDIR to Program Files, when you execute the following line on a x64 machine:

msiexec /i "C:\Temp\MyFirstApp.msi" TARGETDIR="C:\Program Files"


The msiexec will change it back to "C:\Program Files (x86)"


Just so you know why the application is installed in the "C:\Program Files (x86)" folder instead of the "C:\Program Files" folder.

How to show the output of a *.bat or *.cmd file in a WPF application, without waiting for the *.bat file to end


  • The functions
    – process.StandardOutput.ReadToEnd();
    – process.StandardOutput.Read();
    – process.StandardOutput.ReadLine();
    will wait for the process to end and then output the result.
  • If you want to show the output during processing, you should use
    – process.OutputDataReceived += new DataReceivedEventHandler(ProcessOuputHandler);
    – and process.BeginOutputReadLine();
  • Because the BeginOutputReadLine will spawn a new thread, you can’t access the UI directly. If you want to update a textbox, you should use the control.Dispatcher.Invoke function.
  • With the control.Dispatcher.CheckAccess() you can determine if the functions is called from the UI thread or not.
  • [myWpfWindow] is a WPF window containing a textbox with the name [outputTextBox] and a button with the name [testButton].
  • The function [ShowingOutputOfBatFile] is called from a [testButton] click eventhandler




public void ShowingOutputOfBatFile()

    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = @"C:\Temp\Test.bat";
    startInfo.Arguments = "firstParameter secondParamter";
    startInfo.RedirectStandardError = true;
    startInfo.RedirectStandardOutput = true;
    startInfo.UseShellExecute = false;
    startInfo.WorkingDirectory = @"C:\Temp";
    // Use startInfo.CreateNoWindow = HideWindow; if you want to hide the window

    using (Process process = new Process())
        process.StartInfo = startInfo;
        process.OutputDataReceived += new DataReceivedEventHandler(ProcessOuputHandler);
        while (!process.HasExited)
            // Refresh you're WPF window here
            myWpfWindow.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);

public void ProcessOuputHandler(object sendingProcess, DataReceivedEventArgs outLine)
    if (!String.IsNullOrEmpty(outLine.Data))
        if (!outputTextBox.Dispatcher.CheckAccess())
            // Called from a none ui thread, so use dispatcher
            ShowLoggingDelegate showLoggingDelegate = new ShowLoggingDelegate(ShowLogging);
            outputTextBox.Dispatcher.Invoke(DispatcherPriority.Normal, showLoggingDelegate, outLine.Data);
            // Called from UI trhead so just update the textbox

private delegate void ShowLoggingDelegate(string text);
private static Action EmptyDelegate = delegate() { };

/// <summary>
/// Show the logging on screen
/// </summary>
/// <param name="text"></param>
private void ShowLogging(string text)

Setting 100% width and 100% height for a Textbox in WPF

If you want to stretch a textbox to the width of the window in WPF you can use the following code



<Window x:Class="Ada.Eac.UI.DeployWindow"
        Title="DeployWindow" Height="300" Width="988" SnapsToDevicePixels="True" UseLayoutRounding="True" WindowState="Maximized" WindowStartupLocation="CenterScreen" Icon="/Eac;component/Dashboard.ico">
            <ColumnDefinition Width="*"></ColumnDefinition>
            <RowDefinition Height="60"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        <Button Grid.Column="1" Content="Deploy" Height="30" Width="100" HorizontalAlignment="Left" Margin="10,10,10,10" Name="deployButton" Cursor="Hand" />
        <TextBox Grid.Column="1" Grid.Row="2"  HorizontalAlignment="Stretch" Name="outputTextBox" Margin="10,10,10,10" VerticalAlignment="Stretch" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" />





Solving the SSIS 2005 Excel Connection Manager error 0x80040E09

I was getting a 0x80040E09 error, when exporting some rows to an Excel file in SSIS 2005. This was caused by the destination Excel file being read-only. After I cleared the read-only checkbox on the file, the error was resolved.



Error: 0xC0202009 at Data Flow Task, Excel Destination [16]: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E09.
Error: 0xC0047022 at Data Flow Task: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "Excel Destination" (16) failed with error code 0xC0202009. The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure.
Error: 0xC0047021 at Data Flow Task: SSIS Error Code DTS_E_THREADFAILED.  Thread "WorkThread0" has exited with error code 0xC0202009.  There may be error messages posted before this with more information on why the thread has exited.

Solving the SSIS 2005 Excel Connection Manager (Excel Destination) Error 0x80040E21

I was getting as 0x80040E21 error on a SSIS 2005 package when exporting some rows to an Excel file.


In my case this was caused by an input column of the type varchar(max) after converting this column in my t-sql query to a varchar(1024) column the error was resolved.



Error: 0xC0202009 at Data Flow Task, Excel Destination [16]: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E21.
Error: 0xC0202025 at Data Flow Task, Excel Destination [16]: Cannot create an OLE DB accessor. Verify that the column metadata is valid.
Error: 0xC004701A at Data Flow Task, DTS.Pipeline: component "Excel Destination" (16) failed the pre-execute phase and returned error code 0xC0202025.