Is there any tool that can do c# code to powershell Is there any tool that can do c# code to powershell powershell powershell

Is there any tool that can do c# code to powershell


The fastest way to do it is to write the PowerShell code yourself.Below is how the code will look in PowerShell, i would say that most C# developers should be able to grasp the concepts of converting C# code to PowerShell in a very short time.

Functions can be a little odd at the beginning, since the usual PS syntax is

myFunction Parameter1 Parameter2

Also you really should install PowerShell 3.0 and use the Windows PowerShell ISE tool to develop the code.Anyways it should not take you more than 1-2 hours to get your C# code running along in PowerShell.

[System.Reflection.Assembly]::LoadWithPartialName(”Microsoft.SharePoint”) Write-Host "This tool will copy the users from one group to another group"Write-Host "Please enter the URL of the site where your groups are available"[string] $siteUrl = [Console]::ReadLine()$site = new-object Microsoft.SharePoint.SPSite($siteUrl) try{  $web = $site.OpenWeb()  Write-Host "Please enter the name of the source group"  [string] $sourceGroupName = [Console]::ReadLine()  Write-Host "Please enter the name of the destination group"  [string] $destinationGroupName = [Console]::ReadLine()  $sourceUsers = $web.Groups[$sourceGroupName]  (and so on)}catch{  Write-Error ("Failed to copy sharepoint users." + $_)}


It's comments like those above that are turning people away from SO in droves. The OP's question was unambiguous and displayed genuine need.

There are several ways to achieve this. Rewriting your entire C# code repository is not one of them.

As already discussed, as of PS 2 you are able to either run C# (or most any other language) inline, or refer to well-formed external file. I've had mixed success with this and I don't believe it's what the OP was really after.

If you genuinely want to convert code (particularly compiled assemblies) then a decompiler like Reflector is able to do this and - with the PowerShell addon - is also able to convert it on-the-fly.

http://blog.lekman.com/2011/10/converting-c-to-powershell.html

If you want your input and output to take place within the PS console then you'd still have to perform some obvious re-writes. But this method has proved incredibly useful to me.


I doubt there is anything remotely like that, however Visual Studio is not required to compile c# code. You could compile an exe without VS. The compiler (csc.exe) and msbuild are included as part of framework. They are located in C:\Windows\Microsoft.NET\Framework\{version}.

If you really want to call this from powershell, have a look at the Add-Type cmdlet. You provide it the source code and it will compile the source on the fly, then load the assembly into your session.