Skip to content

Instantly share code, notes, and snippets.

View kirillkrylov's full-sized avatar
🏠
Working from home

Kyryl Krylov, CPA kirillkrylov

🏠
Working from home
View GitHub Profile
@mdhorda
mdhorda / PowerShell.cs
Last active October 19, 2023 05:07
Run PowerShell scripts locally or remotely from C#
bool RunPowerShellScript(string script, out IEnumerable<PSObject> output, out string errors)
{
return RunPowerShellScriptInternal(script, out output, out errors, null);
}
bool RunPowerShellScriptRemote(string script, string computer, string username, string password, out IEnumerable<PSObject> output, out string errors)
{
output = Enumerable.Empty<PSObject>();
var credentials = new PSCredential(username, ConvertToSecureString(password));