Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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,
Srivikas
Posted
Comments
Sergey Alexandrovich Kryukov 28-Dec-12 2:24am    
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.
—SA

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:
C#
$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
$form.Add_Click($({
    $this.Controls[0].Text = "Form clicked!"
    $this.Controls[0].ForeColor = [System.Drawing.Color]::Red
}))
[System.Windows.Forms.Application]::Run($form)


[EDIT]

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,
—SA
 
Share this answer
 
v3
Comments
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.
Sergey Alexandrovich Kryukov 28-Dec-12 4:25am    
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.
—SA
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?
—SA
Espen Harlinn 30-Dec-12 8:17am    
5'ed!
Srivikas - You could use something like this. You'll have to check the SharePoint powershell stuff:
C#
using System.Management.Automation;
using System.Management.Automation.Runspaces;

public class PowershellAutomator
{
     private Runspace _runSpace;
     
     public void Automate(string siteName)
     {
          _runSpace = RunspaceFactory.CreateRunspace();
          _runSpace.Open();
          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));
          pipeline.Commands.Add(mySPCmd);
          pipeline.Invoke();      
     }
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900