Click here to Skip to main content
13,596,321 members
Rate this:
Please Sign up or sign in to vote.
Hi friends,

I am a fresher in Sharepoint. I have been assigned a task of making the process of deploying a wsp file automatic. For this I need to develop an .exe file which can do all the stuff. I have checked the codeplex project "Sharepoint Solution Installer". But it is not sufficient for our project. We have to create the site by using this .exe file itself. We should also be able to deploy an entire solution. For this, I thought that PowerShell scripts would be useful. So please help me in achieving this. Any help would be greatly appreciated.

Thanks & Regards,
Posted 27-Dec-12 20:18pm
Do you want to use PowerShell language, entirely, to build a Forms application? This is quite possible, by why?
Or, you need to use PowerShell via some compiled .NET application? This is possible, too.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

As I say, writing a System.Windows.Forms application in PowerShell is quite possible.

I've written this sample code write now while answering to this question. It tool me a couple of minutes. This is fully fledged minimalistic application, even with an event handler and few effects. Run it under PowerShell:
$null = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$form = New-Object System.Windows.Forms.Form
$form.Text = "Hello, PowerShell!"
$form.Padding = 8
$label = New-Object System.Windows.Forms.Label
$label.Autosize = $false
$label.Dock = [System.Windows.Forms.DockStyle]::Top
$label.Text = "Click in the form and see what happens..."
$label.Parent = $form
    $this.Controls[0].Text = "Form clicked!"
    $this.Controls[0].ForeColor = [System.Drawing.Color]::Red


Also, you can embed Power Shell in .NET application. This CodeProject article will give you the idea:
How to run PowerShell scripts from C#[^].

Additionally, you can support it by providing your own cmdlets to the script. Please see these CodeProject articles:
How to Write a Custom PowerShell Cmdlet - Part I[^],
Build a PowerShell cmdlet[^].

Good luck,
Srivikas 28-Dec-12 3:48am
Hi Sergey.. Thanks for your response. I think I went wrong in explaining the question. I need to develop a windows form application which executes power shell scripts. For example, it has to take the name of the web application from the user using our forms and then create a website under that application using powershell commands. Please let me know the way to do that.
Thank you.
I told you, this is possible, too. You have Microsoft.PowerShell and System.Management.Automation. Looks what's in there; you will be able to do it.
Srivikas 28-Dec-12 4:27am
Sure. Thank you.. I shall ask you if I get any doubts
Sergey Alexandrovich Kryukov 28-Dec-12 13:15pm
You are welcome, but no, hold on. I found what I wanted, and also added the references to cmdlet articles. Please see my updated answer, after [EDIT].
This topic is pretty big; so your related questions are welcome.
As to present question, I hope you can already accept this answer formally (green button), will you?
Espen Harlinn 30-Dec-12 8:17am
Sergey Alexandrovich Kryukov 30-Dec-12 11:50am
Thank you, Espen.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Srivikas - You could use something like this. You'll have to check the SharePoint powershell stuff:
using System.Management.Automation;
using System.Management.Automation.Runspaces;

public class PowershellAutomator
     private Runspace _runSpace;
     public void Automate(string siteName)
          _runSpace = RunspaceFactory.CreateRunspace();
          Pipeline pipeline = _runSpace.CreatePipeline();
          // I don't remember what the PowerShell cmdlet is for creating spsite 
          Command mySPCmd = new Command("create-SPSite");
          mySPCmd.Parameters.Add(new CommandParameter("SiteName", siteName));

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.180621.3 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100