Skip to content

Instantly share code, notes, and snippets.

@cat2151
Last active July 17, 2017 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cat2151/7adeddee28664472b331fbd1655dc7c5 to your computer and use it in GitHub Desktop.
Save cat2151/7adeddee28664472b331fbd1655dc7c5 to your computer and use it in GitHub Desktop.
batファイル内のPowerShell内のC#プログラムを動かす
@powershell -NoProfile -ExecutionPolicy Unrestricted "$s=[scriptblock]::create((gc \"%~f0\"|?{$_.readcount -gt 1})-join\"`n\");&$s" %*&goto:eof
# http://qiita.com/cd01/items/82829ba0ec0f59e1b04d
# http://qiita.com/Kosen-amai/items/d68b9590c9e8e8b06377
Param($argBat)
$src = @'
using System;
public static class HelloClass
{
public static string HelloMethod(string arg)
{
string msg = "hello " + arg + " world";
Console.WriteLine(msg);
return msg;
}
}
'@
Add-Type -TypeDefinition $src -Language CSharp
$helloResult = [HelloClass]::HelloMethod($argBat)
Write-Output -InputObject $helloResult
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment