public static bool EnableRemoteControle() { try { PSInvoker invoker = new PSInvoker(); Collection <PSObject> result = invoker.ExecuteCommand(VanScript.FirewallRemoteManagement); result = invoker.ExecuteCommand(VanScript.FirewallRemoteDisk); result = invoker.ExecuteCommand(VanScript.FirewallPing); return(true); } catch (psInvokerException ex) { string exceptionString = string.Empty; foreach (PSObject item in ex.errorRecords) { exceptionString = item.ToString(); logger.Error("Enable Remote Controle psInvokerException : " + item.ToString()); break; } throw new Exception(exceptionString); } catch (Exception ex) { logger.Error("Enable Remote Controle fail : " + ex.ToString()); throw new Exception(ex.ToString()); } }
public static bool IsIscsiConneted() { PSInvoker invoker = new PSInvoker(); Collection <PSObject> result = invoker.ExecuteCommand(VanScript.IsIscsiConnected); return(result.Count == 0 ? false : true); }
public static bool CreateCluster(string clusterName, string clusterComputer, string clusterIP, string ignoreIP = "") { PSInvoker invoker = new PSInvoker(); string createCluster = string.Empty; if (string.IsNullOrEmpty(ignoreIP)) { createCluster = VanScript.CreateClusterNoIgnore(clusterName, clusterComputer, clusterIP); } else { createCluster = VanScript.CreateCluster(clusterName, clusterComputer, clusterIP, ignoreIP); } try { // ProcessCaller.ProcessOpenByPowershell(createCluster); Collection <PSObject> result = invoker.ExecuteCommand(createCluster); } catch (psInvokerException ex) { // logger.Debug("ex string : " + ex.); // logger.Debug("ex Message " + ex.Message); // logger.Debug("ex errorRecords : " + (ex.errorRecords == null ? "false" : ex.errorRecords.Count.ToString())); // logger.Debug("ex Data count : " + ex.Data.Count ?? "false"); foreach (PSObject item in ex.errorRecords) { throw new Exception(item.ToString()); // logger.Debug("ex item value: " + item.ToString()); } // return false; } return(false); }
public static bool CreatePartitionAndFormat(int diskNumber) { PSInvoker invoker = new PSInvoker(); try { string initScript = VanScript.CreateNewPartitionAndFormat(diskNumber); logger.Debug("init Script :" + initScript); Collection <PSObject> result = invoker.ExecuteCommand(initScript); // return result.Count == 1 ? true : false; return(true); } catch (psInvokerException ex) { string exceptionString = string.Empty; foreach (PSObject item in ex.errorRecords) { exceptionString = item.ToString(); logger.Error("Create Partition And Format psInvokerException : " + item.ToString()); break; } throw new Exception(exceptionString); } catch (Exception ex) { logger.Error("Create Partition And Format fail : " + ex.ToString()); return(true); } }
public static bool CreateVSwitch(string adapterName, string switchName) { PSInvoker invoker = new PSInvoker(); logger.Debug("init Script :" + VanScript.CreateVirtualSwitch(adapterName, switchName)); Collection <PSObject> serviceResult = invoker.ExecuteCommand(VanScript.CreateVirtualSwitch(adapterName, switchName)); return(true); }
public static bool NetworkInPrivate() { PSInvoker invoker = new PSInvoker(); Collection <PSObject> serviceResult = invoker.ExecuteCommand(VanScript.GetNetworkType); int networkCount = serviceResult.Where(s => int.Parse(s.ToString()) != 0).Count(); logger.Debug("Network count : " + networkCount); return(networkCount > 0 ? true : false); }
public static bool CheckRDPServiceIsEnable() { PSInvoker invoker = new PSInvoker(); Collection <PSObject> result = invoker.ExecuteCommand(VanScript.CheckRDPfDeny); string rdpfDeny = result[0].ToString(); result = invoker.ExecuteCommand(VanScript.RDPAuthentication); string rdpAuthentication = result[0].ToString(); if (string.Equals("0", rdpfDeny) && string.Equals("0", rdpAuthentication)) { logger.Debug("RDP in success."); return(true); } else { return(false); } }
public static bool VirtualSwitchExist() { PSInvoker invoker = new PSInvoker(); Collection <PSObject> serviceResult = invoker.ExecuteCommand(VanScript.GetVirtualSwitchInfo); string switchInfo = string.Empty; foreach (PSObject item in serviceResult) { switchInfo += item.ToString(); } return(switchInfo.ToLower().Contains(VanScript.VirtaulSwitchName) ? true : false); }
public static List <InstallResult> InstallGPUFeature() { List <InstallResult> installResult = new List <InstallResult>(); try { PSInvoker invoker = new PSInvoker(); Collection <PSObject> result = invoker.ExecuteCommand(VanScript.InstallRemoteDesktopServices); bool success = Convert.ToBoolean(result[0].Members["Success"].Value); bool RestartNeeded = result[0].Members["RestartNeeded"].Value.ToString().ToLower().Contains("yes") ? true : false; installResult.Add(new InstallResult(WindownsFeature.RemoteDesktopServices, success, RestartNeeded)); result = invoker.ExecuteCommand(VanScript.InstallRDSFeature); success = Convert.ToBoolean(result[0].Members["Success"].Value); RestartNeeded = result[0].Members["RestartNeeded"].Value.ToString().ToLower().Contains("yes") ? true : false; installResult.Add(new InstallResult(WindownsFeature.RemoteDesktopServices, success, RestartNeeded)); logger.Debug("install result:" + installResult[0].GetResult()); logger.Debug("install result:" + installResult[1].GetResult()); return(installResult); } catch (psInvokerException ex) { string exceptionString = string.Empty; foreach (PSObject item in ex.errorRecords) { exceptionString = item.ToString(); logger.Error("Install GPU feature fail psInvokerException : " + item.ToString()); break; } throw new Exception(exceptionString); } catch (Exception ex) { logger.Error("Install GPU feature fail : " + ex.ToString()); throw new Exception(ex.ToString()); } }
public static bool CheckWinRMServiceIsEnable() { PSInvoker invoker = new PSInvoker(); Collection <PSObject> serviceResult = invoker.ExecuteCommand(VanScript.GetWinRMStatus); Collection <PSObject> isListening = invoker.ExecuteCommand(VanScript.CheckWinRMIsListening); if (serviceResult.Count == 0 || isListening.Count == 0) { return(false); } string status = serviceResult[0].Properties["status"].Value.ToString(); if (string.Equals(status, "Running")) { return(true); } else { return(false); } }
public static bool EnablePsRemoting() { try { PSInvoker invoker = new PSInvoker(); Collection <PSObject> result; try { result = invoker.ExecuteCommand(VanScript.ChangeNetworkToPrivate); } catch (Exception ex) { logger.Debug("EnablePsRemoting ChangeNetworkToPrivate error:" + ex.ToString()); } result = invoker.ExecuteCommand(VanScript.EnablePsRemoting); result = invoker.ExecuteCommand(VanScript.FirewallPsRemoting); return(true); } catch (Exception ex) { logger.Debug("EnablePsRemoting " + ex.ToString()); return(false); } }
public static bool SetDiskStatus(int diskNumber, bool online) { PSInvoker invoker = new PSInvoker(); try { if (online) { Collection <PSObject> result = invoker.ExecuteCommand(VanScript.SetDiskOnline(diskNumber)); } else { Collection <PSObject> result = invoker.ExecuteCommand(VanScript.SetDiskOffline(diskNumber)); } return(true); } catch (Exception ex) { logger.Debug("SetDiskOnline " + ex.ToString()); return(false); } }
public static bool GetPsRemotingFirewallStatus() { PSInvoker invoker = new PSInvoker(); Collection <PSObject> serviceResults = invoker.ExecuteCommand(VanScript.FirewallPsRemotingStatus); foreach (PSObject item in serviceResults) { if (!bool.Parse(item.Properties["Enabled"].Value.ToString())) { return(false); } } return(true); }
/// <summary> /// one iscsi fit QQ. /// </summary> /// <returns></returns> public static bool IsPersistentConnetionType() { PSInvoker invoker = new PSInvoker(); Collection <PSObject> result = invoker.ExecuteCommand(VanScript.GetIscsiSession); if (result.Count > 0 && (bool)result[0].Properties["IsPersistent"].Value == true) { return(true); } else { return(false); } }
public static bool IsJoinDomain() { PSInvoker invoker = new PSInvoker(); Collection <PSObject> result = invoker.ExecuteCommand(VanScript.GetDomain); string domainInfo = result[0].ToString(); if (string.Compare(domainInfo, "WORKGROUP", true) == 0) { return(false); } else { return(true); } }
public static bool ComputerInCluster() { PSInvoker invoker = new PSInvoker(); try { // ProcessCaller.ProcessOpenByPowershell(createCluster); invoker.ExecuteCommand(VanScript.GetClusterNode); return(true); } catch (Exception ex) { logger.Debug("ComputerInCluster exception: " + ex.ToString()); return(false); } }
public static List <ISCSiInfo> GetVolumeInfo() { List <ISCSiInfo> info = new List <ISCSiInfo>(); PSInvoker invoker = new PSInvoker(); Collection <PSObject> result = invoker.ExecuteCommand(VanScript.GetIscsiInfo); if (result.Count == 0) { throw new Exception("No ISCSi connection."); } foreach (PSObject item in result) { int nubmer = int.Parse(item.Properties["Number"].Value.ToString()); string friendlyName = Convert.ToString(item.Properties["FriendlyName"].Value); bool isOffline = bool.Parse(item.Properties["Isoffline"].Value.ToString()); double partitionSize = double.Parse(item.Properties["Size"].Value.ToString()) / Math.Pow(1024, 3); info.Add(new ISCSiInfo(nubmer, friendlyName, isOffline, partitionSize)); } return(info); }
public static void Reboot() { PSInvoker invoker = new PSInvoker(); invoker.ExecuteCommand(VanScript.Reboot); }
public static void Shutdown() { PSInvoker invoker = new PSInvoker(); invoker.ExecuteCommand(VanScript.Shutdown); }