internal static bool GetUserVisibility(string userName) { var script = $"(Get-ItemProperty -Path '{SpecialAccountRegistry}' -Name {userName}) -eq $null"; var result = ScriptInvoker.InvokeScript(script); return((bool)result.First().BaseObject); }
internal static UserModel GetUser(string userName) { var result = ScriptInvoker .InvokeScript($"Get-WMIObject -Class Win32_UserAccount -Filter \"Name = '{userName}'\"") .FirstOrDefault(); if (result == null) { return(null); } var model = new UserModel { Name = (string)result.Properties["Name"].Value, Description = (string)result.Properties["Description"].Value, FullName = (string)result.Properties["FullName"].Value, Password = null }; var accountExpirationDate = GetPropertyFromAdsi(userName, "AccountExpirationDate"); model.AccountExpires = GetDateProperty(accountExpirationDate); return(model); }
private static object GetProperty(string groupName, string propertyName) { var script = $"(Get-WMIObject -class Win32_Group -Filter \"Name= '{groupName}' and LocalAccount= '$true'\").{propertyName}"; return(ScriptInvoker.InvokeScript(script).FirstOrDefault()?.BaseObject); }
internal static string GetCurrentLoggedUserName() { var script = "(whoami).Split('\\')[1]"; var result = ScriptInvoker.InvokeScript(script).FirstOrDefault()?.BaseObject; return(result as string); }
internal static void HideUser(string userName) { var script = $"New-ItemProperty -Path '{SpecialAccountRegistry}' -Name {userName} -Value 0 -PropertyType DWord -Force"; ScriptInvoker.InvokeScript(script); }
public static List <string> GetMemebers(string groupName) { var script = @"net localgroup " + groupName + " | where { $_ } | select -skip 4"; var result = ScriptInvoker.InvokeScript(script); return(result.Select(p => p.BaseObject as string) .Take(result.Count - 1).ToList()); }
internal static TimeSpan GetPassowrdAge(string userName) { var script = $"([ADSI] \"WinNT://./{userName}, user\").PasswordAge.Value"; var result = (int)(ScriptInvoker.InvokeScript(script).FirstOrDefault()?.BaseObject ?? default(int)); return(TimeSpan.FromSeconds(result)); }
private static void SetPropertyFromAdsi(string userName, string propertyName, string value) { var script = $"$user = [ADSI] (\"WinNT://./{userName}, user\");" + $" $user.{propertyName}.Value = {value};" + $" $user.SetInfo()"; ScriptInvoker.InvokeScript(script); }
public static LocalUserGroup GetGroup(string groupName) { var result = ScriptInvoker.InvokeScript($"Get-WMIObject -Class Win32_Group -Filter \"Name = '{groupName}'\"").FirstOrDefault(); if (result == null) { return(null); } var model = new LocalUserGroup { Name = (string)result.Properties["Name"].Value, Description = (string)result.Properties["Description"].Value, Members = GetMemebers(groupName) }; return(model); }
public static void Remove(string groupName) { ScriptInvoker.InvokeScript($"net localgroup {groupName} /delete"); }
internal static void DeleteUser(string userName) { ScriptInvoker.InvokeScript($"net user {userName} /delete"); }
private static void RemoveFromRegistry(string path) { var script = $"Remove-Item '{path}'"; ScriptInvoker.InvokeScript(script); }
private static void AddToRegistry(string path) { var script = $"New-Item '{path}' -Force"; ScriptInvoker.InvokeScript(script); }
private static object GetPropertyFromWmi(string userName, string propertyName) { var script = $"(Get-WMIObject -Class Win32_UserAccount -Filter \"Name = \'{userName}\'\").{propertyName}"; return(ScriptInvoker.InvokeScript(script).FirstOrDefault()?.BaseObject); }
private static object GetPropertyFromAdsi(string userName, string propertyName) { var script = $"([ADSI] \"WinNT://./{userName}, user\").{propertyName}.Value"; return(ScriptInvoker.InvokeScript(script).FirstOrDefault()?.BaseObject); }
internal static void ShowUser(string userName) { var script = $"Remove-ItemProperty '{SpecialAccountRegistry}' -Name {userName} -Force"; ScriptInvoker.InvokeScript(script); }
internal static void CreateUser(string userName, string userPassword) { ScriptInvoker.InvokeScript($"net user {userName} {userPassword} /add"); }
public static void AssignUser(string groupName, string userName) { var script = $"net localgroup {groupName} {userName} /add"; ScriptInvoker.InvokeScript(script); }
public static void RemoveUser(string groupName, string userName) { var script = $"net localgroup {groupName} {userName} /delete"; ScriptInvoker.InvokeScript(script); }
internal static void SetPassword(string userName, string newPassword) { var script = $"([ADSI] \"WinNT://./{userName}, user\").SetPassword({newPassword})"; ScriptInvoker.InvokeScript(script); }
public static void Create(string groupName) { ScriptInvoker.InvokeScript($"net localgroup {groupName} /add /comment:\"test group to delete\" "); }