本文整理汇总了C#中System.Management.Automation.Runspaces.Runspace.ExecuteShellCommand方法的典型用法代码示例。如果您正苦于以下问题:C# Runspace.ExecuteShellCommand方法的具体用法?C# Runspace.ExecuteShellCommand怎么用?C# Runspace.ExecuteShellCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.Runspaces.Runspace
的用法示例。
在下文中一共展示了Runspace.ExecuteShellCommand方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRdsServerDriveInfo
private List<RdsServerDriveInfo> GetRdsServerDriveInfo(Runspace runspace, string serverName)
{
var result = new List<RdsServerDriveInfo>();
Command cmd = new Command("Get-WmiObject");
cmd.Parameters.Add("Class", "Win32_LogicalDisk");
cmd.Parameters.Add("Filter", "DriveType=3");
cmd.Parameters.Add("ComputerName", serverName);
object[] errors = null;
var psDrives = runspace.ExecuteShellCommand(cmd, false, PrimaryDomainController, out errors);
if (errors.Any())
{
Log.WriteWarning(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
return result;
}
foreach (var psDrive in psDrives)
{
var driveInfo = new RdsServerDriveInfo()
{
VolumeName = RdsRunspaceExtensions.GetPSObjectProperty(psDrive, "VolumeName").ToString(),
DeviceId = RdsRunspaceExtensions.GetPSObjectProperty(psDrive, "DeviceId").ToString(),
SizeMb = Math.Round(Convert.ToDouble(RdsRunspaceExtensions.GetPSObjectProperty(psDrive, "Size")) / 1024 / 1024, 1),
FreeSpaceMb = Math.Round(Convert.ToDouble(RdsRunspaceExtensions.GetPSObjectProperty(psDrive, "FreeSpace")) / 1024 / 1024, 1)
};
result.Add(driveInfo);
}
return result;
}
示例2: GetUserFullName
private string GetUserFullName(string domain, string userName, Runspace runspace)
{
Command cmd = new Command("Get-WmiObject");
cmd.Parameters.Add("Class", "win32_useraccount");
cmd.Parameters.Add("Filter", string.Format("Domain = '{0}' AND Name = '{1}'", domain, userName));
var names = runspace.ExecuteShellCommand(cmd, false, PrimaryDomainController);
if (names.Any())
{
return names.First().Members["FullName"].Value.ToString();
}
return "";
}
示例3: GetServerInfo
private RdsServerInfo GetServerInfo(Runspace runspace, string serverName)
{
var result = new RdsServerInfo();
Command cmd = new Command("Get-WmiObject");
cmd.Parameters.Add("Class", "Win32_Processor");
cmd.Parameters.Add("ComputerName", serverName);
object[] errors = null;
var psProcInfo = runspace.ExecuteShellCommand(cmd, false, PrimaryDomainController, out errors).First();
if (errors.Any())
{
Log.WriteWarning(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
return result;
}
cmd = new Command("Get-WmiObject");
cmd.Parameters.Add("Class", "Win32_OperatingSystem");
cmd.Parameters.Add("ComputerName", serverName);
var psMemoryInfo = runspace.ExecuteShellCommand(cmd, false, PrimaryDomainController, out errors).First();
if (errors.Any())
{
Log.WriteWarning(string.Join("\r\n", errors.Select(e => e.ToString()).ToArray()));
return result;
}
result.NumberOfCores = Convert.ToInt32(RdsRunspaceExtensions.GetPSObjectProperty(psProcInfo, "NumberOfCores"));
result.MaxClockSpeed = Convert.ToInt32(RdsRunspaceExtensions.GetPSObjectProperty(psProcInfo, "MaxClockSpeed"));
result.LoadPercentage = Convert.ToInt32(RdsRunspaceExtensions.GetPSObjectProperty(psProcInfo, "LoadPercentage"));
result.MemoryAllocatedMb = Math.Round(Convert.ToDouble(RdsRunspaceExtensions.GetPSObjectProperty(psMemoryInfo, "TotalVisibleMemorySize")) / 1024, 1);
result.FreeMemoryMb = Math.Round(Convert.ToDouble(RdsRunspaceExtensions.GetPSObjectProperty(psMemoryInfo, "FreePhysicalMemory")) / 1024, 1);
result.Drives = GetRdsServerDriveInfo(runspace, serverName).ToArray();
return result;
}
示例4: EditRdsCollectionSettingsInternal
internal List<string> EditRdsCollectionSettingsInternal(RdsCollection collection, Runspace runspace)
{
object[] errors;
Command cmd = new Command("Set-RDSessionCollectionConfiguration");
cmd.Parameters.Add("CollectionName", collection.Name);
cmd.Parameters.Add("ConnectionBroker", ConnectionBroker);
if (string.IsNullOrEmpty(collection.Settings.ClientDeviceRedirectionOptions))
{
collection.Settings.ClientDeviceRedirectionOptions = "None";
}
var properties = collection.Settings.GetType().GetProperties();
foreach(var prop in properties)
{
if (prop.Name.ToLower() != "id" && prop.Name.ToLower() != "rdscollectionid")
{
var value = prop.GetValue(collection.Settings, null);
if (value != null)
{
cmd.Parameters.Add(prop.Name, value);
}
}
}
runspace.ExecuteShellCommand(cmd, false, PrimaryDomainController, out errors);
if (errors != null)
{
return errors.Select(e => e.ToString()).ToList();
}
return new List<string>();
}
示例5: GetRdsUserSessionsInternal
internal List<RdsUserSession> GetRdsUserSessionsInternal(string collectionName, Runspace runSpace)
{
var result = new List<RdsUserSession>();
var scripts = new List<string>();
scripts.Add(string.Format("Get-RDUserSession -ConnectionBroker {0} - CollectionName {1} | ft CollectionName, Username, UnifiedSessionId, SessionState, HostServer", ConnectionBroker, collectionName));
object[] errors;
Command cmd = new Command("Get-RDUserSession");
cmd.Parameters.Add("CollectionName", collectionName);
cmd.Parameters.Add("ConnectionBroker", ConnectionBroker);
var userSessions = runSpace.ExecuteShellCommand(cmd, false, PrimaryDomainController, out errors);
var properties = typeof(RdsUserSession).GetProperties();
foreach(var userSession in userSessions)
{
object collectionNameObj = RdsRunspaceExtensions.GetPSObjectProperty(userSession, "CollectionName");
object domainName = RdsRunspaceExtensions.GetPSObjectProperty(userSession, "DomainName");
object hostServer = RdsRunspaceExtensions.GetPSObjectProperty(userSession, "HostServer");
object sessionState = RdsRunspaceExtensions.GetPSObjectProperty(userSession, "SessionState");
object unifiedSessionId = RdsRunspaceExtensions.GetPSObjectProperty(userSession, "UnifiedSessionId");
object samAccountName = RdsRunspaceExtensions.GetPSObjectProperty(userSession, "UserName");
var session = new RdsUserSession
{
CollectionName = collectionNameObj != null ? collectionNameObj.ToString() : "",
DomainName = domainName != null ? domainName.ToString() : "",
HostServer = hostServer != null ? hostServer.ToString() : "",
SessionState = sessionState != null ? sessionState.ToString() : "",
UnifiedSessionId = unifiedSessionId != null ? unifiedSessionId.ToString() : "",
SamAccountName = samAccountName != null ? samAccountName.ToString() : ""
};
session.IsVip = false;
session.UserName = GetUserFullName(session.DomainName, session.SamAccountName, runSpace);
result.Add(session);
}
return result;
}
示例6: AddFeature
internal PSObject AddFeature(Runspace runSpace, string featureName, bool includeAllSubFeature = true, bool restart = false)
{
Command cmd = new Command("Add-WindowsFeature");
cmd.Parameters.Add("Name", featureName);
if (includeAllSubFeature)
{
cmd.Parameters.Add("IncludeAllSubFeature", true);
}
if (restart)
{
cmd.Parameters.Add("Restart", true);
}
return runSpace.ExecuteShellCommand(cmd, false, PrimaryDomainController).FirstOrDefault();
}
示例7: ItemExists
internal bool ItemExists(Runspace runSpace, string path)
{
Command testPathCommand = new Command("Test-Path");
testPathCommand.Parameters.Add("Path", path);
var testPathResult = runSpace.ExecuteShellCommand(testPathCommand, false, PrimaryDomainController).First();
var result = Convert.ToBoolean(testPathResult.ToString());
return result;
}
示例8: RemoveItem
internal void RemoveItem(Runspace runSpace, string path)
{
Command rdRapCommand = new Command("Remove-Item");
rdRapCommand.Parameters.Add("Path", path);
rdRapCommand.Parameters.Add("Force", true);
rdRapCommand.Parameters.Add("Recurse", true);
runSpace.ExecuteShellCommand(rdRapCommand, false, PrimaryDomainController);
}
示例9: IsFeatureInstalled
internal bool IsFeatureInstalled(string featureName, Runspace runSpace)
{
bool isInstalled = false;
Command cmd = new Command("Get-WindowsFeature");
cmd.Parameters.Add("Name", featureName);
var feature = runSpace.ExecuteShellCommand(cmd, false, PrimaryDomainController).FirstOrDefault();
if (feature != null)
{
isInstalled = (bool)RdsRunspaceExtensions.GetPSObjectProperty(feature, "Installed");
}
return isInstalled;
}
示例10: AddUserGroupsToCollection
private void AddUserGroupsToCollection(Runspace runSpace, string collectionName, List<string> groups)
{
Command cmd = new Command("Set-RDSessionCollectionConfiguration");
cmd.Parameters.Add("CollectionName", collectionName);
cmd.Parameters.Add("UserGroup", groups);
cmd.Parameters.Add("ConnectionBroker", ConnectionBroker);
runSpace.ExecuteShellCommand(cmd, false, PrimaryDomainController).FirstOrDefault();
}
示例11: ExistRdsServerInDeployment
private bool ExistRdsServerInDeployment(Runspace runSpace, RdsServer server)
{
Command cmd = new Command("Get-RDserver");
cmd.Parameters.Add("Role", "RDS-RD-SERVER");
cmd.Parameters.Add("ConnectionBroker", ConnectionBroker);
var serversPs = runSpace.ExecuteShellCommand(cmd, false, PrimaryDomainController);
if (serversPs != null)
{
foreach (var serverPs in serversPs)
{
var serverName = Convert.ToString(RdsRunspaceExtensions.GetPSObjectProperty(serverPs, "Server"));
if (string.Compare(serverName, server.FqdName, StringComparison.InvariantCultureIgnoreCase) == 0)
{
return true;
}
}
}
return false;
}
示例12: AddRdsServerToDeployment
private void AddRdsServerToDeployment(Runspace runSpace, RdsServer server)
{
Command cmd = new Command("Add-RDserver");
cmd.Parameters.Add("Server", server.FqdName);
cmd.Parameters.Add("Role", "RDS-RD-SERVER");
cmd.Parameters.Add("ConnectionBroker", ConnectionBroker);
runSpace.ExecuteShellCommand(cmd, false, PrimaryDomainController);
}
示例13: DeleteCertificateFile
private object[] DeleteCertificateFile(string destinationPath, Runspace runspace)
{
var scripts = new List<string>
{
string.Format("Remove-Item -Path \"{0}\" -Force", destinationPath)
};
object[] errors = null;
runspace.ExecuteShellCommand(scripts, out errors);
return errors;
}
示例14: CopyCertificateFile
private object[] CopyCertificateFile(Runspace runspace, string filePath, string destinationPath)
{
var scripts = new List<string>
{
string.Format("Copy-Item \"{0}\" -Destination \"{1}\" -Force", filePath, destinationPath)
};
object[] errors = null;
runspace.ExecuteShellCommand(scripts, out errors);
return errors;
}