本文整理匯總了C#中System.Management.Automation.PSCmdlet.WriteVerbose方法的典型用法代碼示例。如果您正苦於以下問題:C# PSCmdlet.WriteVerbose方法的具體用法?C# PSCmdlet.WriteVerbose怎麽用?C# PSCmdlet.WriteVerbose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Management.Automation.PSCmdlet
的用法示例。
在下文中一共展示了PSCmdlet.WriteVerbose方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AliasDefinitionsTypeValidationCallback
private static bool AliasDefinitionsTypeValidationCallback(string key, object obj, PSCmdlet cmdlet, string path)
{
Hashtable[] hashtableArray = DISCPowerShellConfiguration.TryGetHashtableArray(obj);
if (hashtableArray == null)
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustBeHashtableArray, key, path));
return false;
}
foreach (Hashtable hashtable in hashtableArray)
{
if (!hashtable.ContainsKey(AliasNameToken))
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustContainKey, new object[] { key, AliasNameToken, path }));
return false;
}
if (!hashtable.ContainsKey(AliasValueToken))
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustContainKey, new object[] { key, AliasValueToken, path }));
return false;
}
foreach (string str in hashtable.Keys)
{
if ((!string.Equals(str, AliasNameToken, StringComparison.OrdinalIgnoreCase) && !string.Equals(str, AliasValueToken, StringComparison.OrdinalIgnoreCase)) && (!string.Equals(str, AliasDescriptionToken, StringComparison.OrdinalIgnoreCase) && !string.Equals(str, AliasOptionsToken, StringComparison.OrdinalIgnoreCase)))
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeContainsInvalidKey, new object[] { str, key, path }));
return false;
}
}
}
return true;
}
示例2: RestartWinRMService
/// <summary>
/// Run script to restart the WinRM service. The script will write
/// output and error into the cmdlets streams.
/// </summary>
/// <param name="cmdlet">
/// Cmdlet's context in which the restart-service script is run.
/// </param>
/// <param name="isErrorReported">
/// if true, then this method is a no-op.
/// </param>
/// <param name="force">
/// if true, then the user will not be prompted.
/// </param>
/// <param name="noServiceRestart">
/// if true, we dont attempt to restart winrm service ie. this will be a no-op.
/// </param>
internal static void RestartWinRMService(PSCmdlet cmdlet, bool isErrorReported, bool force, bool noServiceRestart)
{
// restart the service only if there is no error running WSMan config command
if (!(isErrorReported || noServiceRestart))
{
// restart-service winrm to make the changes effective.
string restartServiceAction = RemotingErrorIdStrings.RestartWSManServiceAction;
string restartServiceTarget = StringUtil.Format(RemotingErrorIdStrings.RestartWSManServiceTarget, "WinRM");
if (force || cmdlet.ShouldProcess(restartServiceTarget, restartServiceAction))
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.RestartWSManServiceMessageV));
ScriptBlock restartServiceScript = cmdlet.InvokeCommand.NewScriptBlock(restartWSManFormat);
var emptyArray = Utils.EmptyArray<object>();
restartServiceScript.InvokeUsingCmdlet(
contextCmdlet: cmdlet,
useLocalScope: true,
errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe,
dollarUnder: AutomationNull.Value,
input: emptyArray,
scriptThis: AutomationNull.Value,
args: emptyArray);
}
}
}
示例3: ExecuteCmdletBase
//.........這裏部分代碼省略.........
QueryMapResultConsumer domainNodesConsumer = new QueryMapResultConsumer();
using (MappingToolDatabaseDataContext mapDatabaseContext = new MappingToolDatabaseDataContext(MapDatabaseConnectionString))
{
mapDatabaseContext.CommandTimeout = 600;
var domainNodes = from node in mapDatabaseContext.Nodes
where node.NodeTypeUid.HasValue && node.NodeTypeUid.Value == DomainNodeType
select node;
if (domainNodes != null && domainNodes.Count() > 0)
{
foreach (var domainNode in domainNodes)
{
var domainMaps = mapDatabaseContext.QueryMapMultiDepth(domainNode.DomainUid, domainNode.NodeUid, 1, true);
domainNodesConsumer.Consume(domainMaps);
}
}
var rootMaps = from qNode in domainNodesConsumer.Nodes.Values
select qNode.NodeUid;
DateTime startTime = new DateTime(2014, 04, 01, 0, 0, 0);
foreach (var map in domainNodesConsumer.Nodes.Values)
{
if (map.NodeTypeUid.HasValue && map.NodeTypeUid != DomainNodeType)
{
QueryMapResultConsumer mapNodesConsumer = new QueryMapResultConsumer();
DbIntegrityUtilities integrityUtilities = new DbIntegrityUtilities(mapNodesConsumer);
var mapNodes = mapDatabaseContext.QueryMapMultiDepth(map.DomainUid, map.NodeUid, -1, false);
callingCmdlet.WriteVerbose("Processing nodes");
mapNodesConsumer.Consume(mapNodes);
integrityUtilities.DetectAndFixMapCollisions(callingCmdlet, mapDatabaseContext, rootMaps, false, false);
callingCmdlet.WriteVerbose("Finished processing nodes");
callingCmdlet.WriteVerbose("Processing nodes and related metadata");
foreach (var node in mapNodesConsumer.Nodes.Values)
{
var dbNodes = from qNode in mapDatabaseContext.Nodes
where qNode.NodeUid == node.NodeUid
select qNode;
if (dbNodes != null && dbNodes.Count() > 0)
{
var dbNode = dbNodes.First();
dbNode.Created = startTime;
dbNode.Modified = startTime;
dbNode.RootMapUid = map.NodeUid;
foreach (var dbMetadata in dbNode.Metadatas)
{
dbMetadata.Created = startTime;
dbMetadata.Modified = startTime;
if (dbMetadata.DomainUid == null)
{
dbMetadata.DomainUid = map.DomainUid;
}
if (dbMetadata.RootMapUid == null)
{
dbMetadata.RootMapUid = map.NodeUid;
示例4: ExecuteCmdletBase
//.........這裏部分代碼省略.........
orphanedNodes.Add(node.NodeUid);
}
/// Find all the orphaned relationships.
FindOrphanedRelationships(ref orphanedRelationships, node);
}
}
#endregion
int orphanedNodesCount = 0;
int orphanedMetadataCount = 0;
int orphanedDescriptorsCount = 0;
int orphanedRelationshipsCount = 0;
foreach (Guid nodeId in orphanedNodes)
{
var orphanedDescriptors = from dbDescriptor in dataContext.Descriptors
where dbDescriptor.NodeUid == nodeId
select dbDescriptor;
foreach (var orphanedDescriptor in orphanedDescriptors)
{
dataContext.Descriptors.DeleteOnSubmit(orphanedDescriptor);
orphanedDescriptorsCount++;
}
var orphanedMetadata = from dbMetadata in dataContext.Metadatas
where dbMetadata.NodeUid == nodeId
select dbMetadata;
foreach (var orphanedMetadatum in orphanedMetadata)
{
dataContext.Metadatas.DeleteOnSubmit(orphanedMetadatum);
orphanedMetadataCount++;
}
}
dataContext.SubmitChanges();
foreach (Guid relationshipId in orphanedRelationships)
{
var orphanedDescriptors = from dbDescriptor in dataContext.Descriptors
where dbDescriptor.RelationshipUid == relationshipId
select dbDescriptor;
foreach (var orphanedDescriptor in orphanedDescriptors)
{
dataContext.Descriptors.DeleteOnSubmit(orphanedDescriptor);
orphanedDescriptorsCount++;
}
var orphanedMetadata = from dbMetadata in dataContext.Metadatas
where dbMetadata.RelationshipUid == relationshipId
select dbMetadata;
foreach (var orphanedMetadatum in orphanedMetadata)
{
dataContext.Metadatas.DeleteOnSubmit(orphanedMetadatum);
orphanedMetadataCount++;
}
}
dataContext.SubmitChanges();
foreach (Guid nodeId in orphanedNodes)
{
var orphanedDbNodes = from dbNode in dataContext.Nodes
where dbNode.NodeUid == nodeId
select dbNode;
foreach (var orphanedNode in orphanedDbNodes)
{
dataContext.Nodes.DeleteOnSubmit(orphanedNode);
orphanedNodesCount++;
}
}
dataContext.SubmitChanges();
foreach (Guid relationshipId in orphanedRelationships)
{
var orphanedDbRelationships = from dbRelationship in dataContext.Relationships
where dbRelationship.RelationshipUid == relationshipId
select dbRelationship;
foreach (var orphanedRelationship in orphanedDbRelationships)
{
dataContext.Relationships.DeleteOnSubmit(orphanedRelationship);
orphanedRelationshipsCount++;
}
}
dataContext.SubmitChanges();
callingCmdlet.WriteVerbose(string.Format("Deleted {0} orphaned node/s.", orphanedNodesCount));
callingCmdlet.WriteVerbose(string.Format("Deleted {0} orphaned relationship/s.", orphanedRelationshipsCount));
callingCmdlet.WriteVerbose(string.Format("Deleted {0} orphaned metadata/s.", orphanedMetadataCount));
callingCmdlet.WriteVerbose(string.Format("Deleted {0} orphaned descriptor/s.", orphanedDescriptorsCount));
}
}
示例5: CheckRuleExtension
public Dictionary<string, List<string>> CheckRuleExtension(string[] path, PSCmdlet cmdlet)
{
Dictionary<string, List<string>> results = new Dictionary<string, List<string>>();
List<string> invalidPaths = new List<string>();
List<string> validDllPaths = new List<string>();
List<string> validModPaths = new List<string>();
// Gets valid module names
foreach (string childPath in path)
{
try
{
cmdlet.WriteVerbose(string.Format(CultureInfo.CurrentCulture, Strings.CheckModuleName, childPath));
string resolvedPath = string.Empty;
// Users may provide a valid module path or name,
// We have to identify the childPath is really a directory or just a module name.
// You can also consider following two commands.
// Get-ScriptAnalyzerRule -RuleExtension "ContosoAnalyzerRules"
// Get-ScriptAnalyzerRule -RuleExtension "%USERPROFILE%\WindowsPowerShell\Modules\ContosoAnalyzerRules"
if (Path.GetDirectoryName(childPath) == string.Empty)
{
resolvedPath = childPath;
}
else
{
resolvedPath = cmdlet.SessionState.Path
.GetResolvedPSPathFromPSPath(childPath).First().ToString();
}
using (System.Management.Automation.PowerShell posh =
System.Management.Automation.PowerShell.Create())
{
string script = string.Format(CultureInfo.CurrentCulture, "Get-Module -Name '{0}' -ListAvailable", resolvedPath);
PSModuleInfo moduleInfo = posh.AddScript(script).Invoke<PSModuleInfo>().First();
// Adds original path, otherwise path.Except<string>(validModPaths) will fail.
// It's possible that user can provide something like this:
// "..\..\..\ScriptAnalyzer.UnitTest\modules\CommunityAnalyzerRules\CommunityAnalyzerRules.psd1"
if (moduleInfo.ExportedFunctions.Count > 0) validModPaths.Add(childPath);
}
}
catch
{
// User may provide an invalid module name, like c:\temp.
// It's a invalid name for a Windows PowerShell module,
// But we need test it further since we allow user to provide a folder to extend rules.
// You can also consider following two commands.
// Get-ScriptAnalyzerRule -RuleExtension "ContosoAnalyzerRules", "C:\Temp\ExtendScriptAnalyzerRules.dll"
// Get-ScriptAnalyzerRule -RuleExtension "ContosoAnalyzerRules", "C:\Temp\"
continue;
}
}
// Gets valid dll paths
foreach (string childPath in path.Except<string>(validModPaths))
{
try
{
string resolvedPath = cmdlet.SessionState.Path
.GetResolvedPSPathFromPSPath(childPath).First().ToString();
cmdlet.WriteDebug(string.Format(CultureInfo.CurrentCulture, Strings.CheckAssemblyFile, resolvedPath));
if (String.Equals(Path.GetExtension(resolvedPath),".dll", StringComparison.OrdinalIgnoreCase))
{
if (!File.Exists(resolvedPath))
{
invalidPaths.Add(resolvedPath);
continue;
}
}
else
{
if (!Directory.Exists(resolvedPath))
{
invalidPaths.Add(resolvedPath);
continue;
}
}
validDllPaths.Add(resolvedPath);
}
catch
{
invalidPaths.Add(childPath);
}
}
// Resloves relative paths.
try
{
for (int i = 0; i < validModPaths.Count; i++)
{
validModPaths[i] = cmdlet.SessionState.Path
.GetResolvedPSPathFromPSPath(validModPaths[i]).First().ToString();
}
for (int i = 0; i < validDllPaths.Count; i++)
//.........這裏部分代碼省略.........
示例6: RestartWinRMService
internal static void RestartWinRMService(PSCmdlet cmdlet, bool isErrorReported, bool force, bool noServiceRestart)
{
if (!isErrorReported && !noServiceRestart)
{
string restartWSManServiceAction = RemotingErrorIdStrings.RestartWSManServiceAction;
string target = StringUtil.Format(RemotingErrorIdStrings.RestartWSManServiceTarget, "WinRM");
if (force || cmdlet.ShouldProcess(target, restartWSManServiceAction))
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.RestartWSManServiceMessageV, new object[0]));
cmdlet.InvokeCommand.NewScriptBlock("restart-service winrm -force -confirm:$false").InvokeUsingCmdlet(cmdlet, true, ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, AutomationNull.Value, new object[0], AutomationNull.Value, new object[0]);
}
}
}
示例7: ExecuteCmdletBase
//.........這裏部分代碼省略.........
relationship.DomainUid = DestinationDomain.DomainId;
relationship.RelationshipTypeUid = queryMapResult.RelationshipTypeUid;
relationship.RootMapUid = queryMapResult.RootMapUid;
relationship.Created = queryMapResult.Created;
relationship.Modified = queryMapResult.Modified;
relationship.CreatedBy = queryMapResult.CreatedBy;
relationship.ModifiedBy = queryMapResult.ModifiedBy;
originalRelationships.Add(relationship);
}
}
}
queryMapResultSet = queryMapResultSets.GetResult<QueryMapMultiDepthResult>();
}
}
int totalNodes = originalNodes.Count;
int totalRelationships = originalRelationships.Count;
int totalMetadata = originalMetadata.Count;
int totalDescriptors = originalDescriptors.Count;
Dictionary<Guid, Guid> newNodeIds = new Dictionary<Guid, Guid>();
Dictionary<Guid, Guid> newRelationshipIds = new Dictionary<Guid, Guid>();
Model.IDatabaseInfo destinationDomainDbInfo = DestinationDomain;
/// The following performs the creation of nodes in the new database
using (MappingToolDatabaseDataContext dataContext = new MappingToolDatabaseDataContext(destinationDomainDbInfo.ConnectionString))
{
dataContext.CommandTimeout = 180;
int count = 0;
callingCmdlet.WriteVerbose("Processing of nodes starting.");
DateTime currentTime = DateTime.Now;
WindowsIdentity currentUserIdentity = WindowsIdentity.GetCurrent();
string currentUserName = "anonymous";
if (currentUserIdentity != null)
{
currentUserName = currentUserIdentity.Name;
}
Guid newRootMapId = Guid.NewGuid();
/// If it is the root map node, we want to assign it the pre-determined ID as we've been using this as the RootMapUid for everything;
QueryMapNode sourceMapNode = originalNodes[SourceMap.NodeId];
Node newRootMapNode = new Node();
newRootMapNode.NodeUid = newRootMapId;
newRootMapNode.DomainUid = DestinationDomain.DomainId;
newRootMapNode.NodeTypeUid = sourceMapNode.NodeTypeUid;
newRootMapNode.RootMapUid = newRootMapId;
newRootMapNode.Created = sourceMapNode.Created;
newRootMapNode.Modified = currentTime;
newRootMapNode.CreatedBy = sourceMapNode.CreatedBy;
newRootMapNode.ModifiedBy = currentUserName;
newNodeIds[sourceMapNode.NodeUid] = newRootMapNode.NodeUid;
dataContext.Nodes.InsertOnSubmit(newRootMapNode);
/// Iterate through all nodes in memory and change their node IDs and root map IDs so that they won't clash with the map from where they were copied.
foreach (QueryMapNode memoryNode in originalNodes.Values)
示例8: VerifyConfigTable
internal static bool VerifyConfigTable(Hashtable table, PSCmdlet cmdlet, string path)
{
bool flag = false;
foreach (DictionaryEntry entry in table)
{
if (!ConfigFileContants.IsValidKey(entry, cmdlet, path))
{
return false;
}
if (entry.Key.ToString().Equals(ConfigFileContants.SchemaVersion, StringComparison.OrdinalIgnoreCase))
{
flag = true;
}
}
if (!flag)
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCMissingSchemaVersion, path));
return false;
}
try
{
ValidateAbsolutePaths(cmdlet.SessionState, table, path);
ValidateExtensions(table, path);
}
catch (InvalidOperationException exception)
{
cmdlet.WriteVerbose(exception.Message);
return false;
}
return true;
}
示例9: ExecutionPolicyValidationCallback
private static bool ExecutionPolicyValidationCallback(string key, object obj, PSCmdlet cmdlet, string path)
{
string str = obj as string;
if (!string.IsNullOrEmpty(str))
{
try
{
Enum.Parse(DISCUtils.ExecutionPolicyType, str, true);
return true;
}
catch (ArgumentException)
{
}
}
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustBeValidEnum, new object[] { key, DISCUtils.ExecutionPolicyType.FullName, LanguagePrimitives.EnumSingleTypeConverter.EnumValues(DISCUtils.ExecutionPolicyType), path }));
return false;
}
示例10: StringTypeValidationCallback
private static bool StringTypeValidationCallback(string key, object obj, PSCmdlet cmdlet, string path)
{
if (obj is string)
{
return true;
}
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustBeString, key, path));
return false;
}
示例11: StringOrHashtableArrayTypeValidationCallback
private static bool StringOrHashtableArrayTypeValidationCallback(string key, object obj, PSCmdlet cmdlet, string path)
{
if (DISCPowerShellConfiguration.TryGetObjectsOfType<object>(obj, new Type[] { typeof(string), typeof(Hashtable) }) == null)
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustBeStringOrHashtableArrayInFile, key, path));
return false;
}
return true;
}
示例12: StringArrayTypeValidationCallback
private static bool StringArrayTypeValidationCallback(string key, object obj, PSCmdlet cmdlet, string path)
{
if (DISCPowerShellConfiguration.TryGetStringArray(obj) == null)
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustBeStringArray, key, path));
return false;
}
return true;
}
示例13: IsValidKey
internal static bool IsValidKey(DictionaryEntry de, PSCmdlet cmdlet, string path)
{
bool flag = false;
foreach (ConfigTypeEntry entry in ConfigFileKeys)
{
if (string.Equals(entry.Key, de.Key.ToString(), StringComparison.OrdinalIgnoreCase))
{
flag = true;
if (entry.ValidationCallback(de.Key.ToString(), de.Value, cmdlet, path))
{
return true;
}
}
}
if (!flag)
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCInvalidKey, de.Key.ToString(), path));
}
return false;
}
示例14: ISSValidationCallback
private static bool ISSValidationCallback(string key, object obj, PSCmdlet cmdlet, string path)
{
string str = obj as string;
if (!string.IsNullOrEmpty(str))
{
try
{
Enum.Parse(typeof(System.Management.Automation.Remoting.SessionType), str, true);
return true;
}
catch (ArgumentException)
{
}
}
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustBeValidEnum, new object[] { key, typeof(System.Management.Automation.Remoting.SessionType).FullName, LanguagePrimitives.EnumSingleTypeConverter.EnumValues(typeof(System.Management.Automation.Remoting.SessionType)), path }));
return false;
}