本文整理汇总了C#中System.Management.Automation.PSCmdlet.WriteDebug方法的典型用法代码示例。如果您正苦于以下问题:C# PSCmdlet.WriteDebug方法的具体用法?C# PSCmdlet.WriteDebug怎么用?C# PSCmdlet.WriteDebug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.PSCmdlet
的用法示例。
在下文中一共展示了PSCmdlet.WriteDebug方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateOrderMatrix
internal static List<OrderByPropertyEntry> CreateOrderMatrix(PSCmdlet cmdlet, List<PSObject> inputObjects, List<MshParameter> mshParameterList)
{
List<OrderByPropertyEntry> list = new List<OrderByPropertyEntry>();
foreach (PSObject obj2 in inputObjects)
{
if ((obj2 != null) && (obj2 != AutomationNull.Value))
{
List<ErrorRecord> errors = new List<ErrorRecord>();
List<string> propertyNotFoundMsgs = new List<string>();
OrderByPropertyEntry item = OrderByPropertyEntryEvaluationHelper.ProcessObject(obj2, mshParameterList, errors, propertyNotFoundMsgs);
foreach (ErrorRecord record in errors)
{
cmdlet.WriteError(record);
}
foreach (string str in propertyNotFoundMsgs)
{
cmdlet.WriteDebug(str);
}
list.Add(item);
}
}
return list;
}
示例2: 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++)
//.........这里部分代码省略.........