This project is read-only.

Log/Trace options, Write-Host function and different hosts to run PowerShell scripts

Apr 22, 2013 at 3:57 AM
Hi team,

It is sort of rare cases. However, I'd like to give it a try.

I had several projects where we did a "MSI/Windows installer like" installation experience for the end users. We wrote Powershell scripts to get SharePoint solution deployed. Also, we wrote a .NET application (just pure WinForms) which runs a PowerShell host and executes PowerShell scripts for solution deployment. Hence, we had only one PowerShell script to be used by administrator/developers (just pure console run) and by WinForms app (to provide end user experience).

Surely, I wouldn't say that it is a "common" case to be concerned of. Having ".NET app host" as a PowerShell host lead us to either not use "Write-Host" function (and some other functions) or spent a lot of time to make sure PowerShell script could be run under custom PowerShell host.

So, here is the question - is there any fast and cheap way to "host" and run SPSD with"custom PowerShell host" under .NET application? Have you had any ideas around that or road maps for the future releases?
Apr 22, 2013 at 8:24 AM
Edited Apr 22, 2013 at 4:10 PM

in the previous MSBuild version of SPSD, we had implemented the possibilty to show dialogs to get information like target application or credentials from the enduser.
This hasn't been migrated yet to the new PS version. But we are also not really sure how many people actually need something like that, as SPSD is ususaly used in controlled staging environments by admins or like we do it as automated staging solution through Team Foundation Server.

But this is not entirely the answer to your question :) Actually we have already thought about that, but it is not yet entirely implemented.

At the moment SPSD uses Write-Host and Transcripting to provide output and logging. As you say this is not easily possible in a custom host.
We have already planed to migrate the "old" logging style from the previous MSBuild version of SPSD. That one will allow to log into a file using the ULS logging format instead of writing it into the console output.

For now, if you want to re-route all loggings then the easiest way is to disable the "Start/StopTracing" functions in SPSD_Utilities.ps1 and change the Write-Host commands in the Log function (same ps1). There should be no other place in SPSD where Write-Host is used.
Additonally you might require to comment out the line in SPSD_Base.ps1/StartUp where the window title is set, as I suppose this will not be possible either.

The scripts themselves can be easily started without the batchfiles of course. You just need to pass the appropriate parameters.
Hope that helps.


Apr 22, 2013 at 8:24 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.