internal static bool Exist(string name) { var command = $"Get-Service {name} -ErrorAction Ignore"; var result = ScriptInvoker.InvokeScript(command); return(result.Any()); }
public static void AssingnUserToAdministators(string userName) { var getAdminGroupNameScript = "(Get-WMIObject -class Win32_Group -Filter \"SID= 'S-1-5-32-544' and LocalAccount= '$true'\").Name"; var adminGroupName = ScriptInvoker.InvokeScript(getAdminGroupNameScript).FirstOrDefault()?.BaseObject as string; var assignUserToGroupScript = $"net localgroup {adminGroupName} {userName} /add"; ScriptInvoker.InvokeScript(assignUserToGroupScript); }
public static void CreateUser(string userName, string userPassword) { ScriptInvoker.InvokeScript($"net user {userName} {userPassword} /add"); }
public static void DeleteUser(string userName) { ScriptInvoker.InvokeScript($"net user {userName} /delete"); }
private static ICollection <PSObject> GetProperties(string serviceName, string property) { var command = $@"(Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Services\{serviceName}').{property}"; return(ScriptInvoker.InvokeScript(command)); }