PS> Add-Type -outputtype consoleapplication -outputassembly helloworld.exe 'public class helloworld{public static void Main(){System.Console.WriteLine("hello world");}}'
PS> .\helloworld.exe
hello world
Probably my first .exe this century 🙂
PS> Add-Type -outputtype consoleapplication -outputassembly helloworld.exe 'public class helloworld{public static void Main(){System.Console.WriteLine("hello world");}}'
PS> .\helloworld.exe
hello world
Probably my first .exe this century 🙂
and this will work on machines without powershell?
No, this Add-Type is 100% powershell, but powershell is free to download and supported by Microsoft (if you are using Windows at all 😉 )
That is supported, is okay, but in some environments is not really welcome, if i want to use it. 😉
actually you do not need powershell at all, only .net
try this
C:\> type helloworld.cs
class HelloWorld
{
static void Main() {
System.Console.WriteLine("Hello World");
}
}
C:\> C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\csc.exe .\helloworld.cs
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.
C:\> dir helloworld.*
09.05.2012 17:49 103 helloworld.cs
09.05.2012 17:52 3'584 helloworld.exe
C:\> helloworld
Hello World
Thanks for the tipp. Actually, powershell has many other usefull functions, what i want to use in a script, but always, if i want to use that scripts, i see, that on that environment ( mostly servers ) powershell is not installed. For such environments would have been interesting, to use the functions from powershell, without an installation of powershell, if there is an possibility to make an executable from the script.
is it not installed by default on w2k8 server and later ?
Maybe. I don’t know. I don’t test on w2k8 servers, only on older. Not the hole world takes all the security advices really taken seriously. 😉 not spoken from supports, but this is an another story…
powershell is pre-installed on windows 7 in its version 2.0, but u can still get the version 1.0 for windows vista or XP from the windows update.
as for windows server 2008, it’s pre-installed however u’ve to go and activate it by using the “Add a feature” option of ur Server Manager.
@gaspyr thanks for the hint on how to activate it in w2k8