Last active
October 3, 2016 18:45
-
-
Save dbroeglin/7ef7f979da85b5f40193f1b2a63fea50 to your computer and use it in GitHub Desktop.
An excerpt from Vagrant that illustrates use of C# inside PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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