Returning Events with PowerShellRSS

2 replies

Last post Feb 23, 2009 03:47 AM by sergeia

  • Returning Events with PowerShell

    Feb 17, 2009 09:58 PM|wulfmaer|LINK

    Hello, Everyone.

    I'm trying to figure out how I can use PowerShell to trigger scripts and then report events (like "install succeeded" or "failed" or "task completed" or "did not complete" or "current percentage of completion")  to a C# web application which is triggering the scripts on remote machines.

    Let me explain, I'm an SDET in Seattle and I've just deployed a very nice batch and cmd file driven lab teardown and deployment system which has really helped cutdown the time it takes us to teardown our test environment and then deploy a new build. Anyway, I wrote a C# web application to serve as a master control for triggering all the teardown and deployment scripts that we use and it works great, but I don't have any status reporting. My C# web application can't tell when a remote process it triggered via a script it launched completed successfully or not. Specifically, I'm using a web application written in C# running on IIS7 to launch local cmd files which use psexec.exe to call scripts on remote machines but my C# application never gets notified what happened after the initial scripts are launched.

    For example, I click a button on my web application and it launches a local script which, in turn, calls a remote cmd script containing the following instructions:

    "REM triggers all machines in ms_targets.txt to uninstall/teardown mymediaserver

    psexec \\ -i -d -n 5 -u wulf -p xxx C:\setups\master_teardowns\mymediaserver\master_mediaserver_teardown.cmd"

    This script (master_mediaserver_teardown.cmd) contains the following instructions (quotations added for readability and are not in the script):

    "REM silently uninstalls mymediaserver using the app's product code

    net stop mymediaserver
    MsiExec.exe /uninstall {3FD3D21F-629F-4174-AF7B-29F4DA927B38} /quiet"

    Now, when this script is launched on a remote machine a DOS command-window opens up on that machine and you can see what the progress of the uninstall process is if you're sitting right there looking at its monitor. But the C# web application which launched the script in the first place knows nothing of the status/progress of this process as the uninstallation is performed. And again, when the process completes, I don't currently have a method of communicating back to the C# website which launched the process, via script, that the process has completed.

    I sure hope I'm making sense here...
    Now, I'm using installshield for all my install packages and psexec.exe, triggered by my C# web application, is what is being used to launch these installers. Can PowerShell be used in someway to create an object which communicates events back to the C# web application? Or, perhaps, is there something that I'm not doing correctly or am missing with my windows scripting that would return status (not just error codes) to the web application?

    Ideally, I'd like to show status bars on my C# web application which increment as the various remote installations and or teardowns are underway as well as show when tasks have completed and whether or not any errors occurred.

    Any feedback would be most appreciated!



  • Re: Returning Events with PowerShell

    Feb 18, 2009 03:00 PM|wulfmaer|LINK

     Thanks. But I kinda lost you after "woot..."


  • Re: Returning Events with PowerShell

    Feb 23, 2009 03:47 AM|sergeia|LINK


    Hi, wulfmaer!

    Your question is a little bit generic, so I will try to provide generic answer.

    To generate events you will need to wrap functionality of msiexec into your own code. If you want to use PowerShell, it probably will be easier to wrap it into managed code. There is a description of Microsoft Installer APIs on MSDN. You could then write or find somewhere interop for these APIs. After that you will launch installation from your code, which could be Powershell cmdlet or managed object, created in Powershell. You could run remote scripts and use events in Powershell v2.0, which is not released yet, but available as CTP. There is also third party eventing support that supposed to work with released version.

    Otherwise, if you have managed code that controls installation, you could display result on the Web page.


    Hope this will help you,