Skip to content

Instantly share code, notes, and snippets.

@dbroeglin
Last active October 3, 2016 18:45
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 dbroeglin/7ef7f979da85b5f40193f1b2a63fea50 to your computer and use it in GitHub Desktop.
Save dbroeglin/7ef7f979da85b5f40193f1b2a63fea50 to your computer and use it in GitHub Desktop.
An excerpt from Vagrant that illustrates use of C# inside PowerShell
function ShuttingDown {
[string]$sourceCode = @"
using System;
using System.Runtime.InteropServices;
namespace Vagrant {
public static class RemoteManager {
private const int SM_SHUTTINGDOWN = 0x2000;
[DllImport("User32.dll", CharSet = CharSet.Unicode)]
private static extern int GetSystemMetrics(int Index);
public static bool Shutdown() {
return (0 != GetSystemMetrics(SM_SHUTTINGDOWN));
}
}
}
"@
$type = Add-Type -TypeDefinition $sourceCode -PassThru
return $type::Shutdown()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment