Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP PowerShell Sharepoint , +
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 27-Dec-12 21:18pm
Comments
Sergey Alexandrovich Kryukov at 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
Rate this: bad
good
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
$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
  Permalink  
v3
Comments
Srivikas at 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 at 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 at 28-Dec-12 4:27am
   
Sure. Thank you.. I shall ask you if I get any doubts
Sergey Alexandrovich Kryukov at 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 at 30-Dec-12 8:17am
   
5'ed!
Sergey Alexandrovich Kryukov at 30-Dec-12 11:50am
   
Thank you, Espen.
—SA
Rate this: bad
good
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();
          _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();      
     }
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 515
1 Maciej Los 340
2 Richard MacCutchan 265
3 BillWoodruff 225
4 Mathew Soji 155
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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