当前位置: 首页>>代码示例>>C#>>正文


C# ScriptBlock.GetPowerShell方法代码示例

本文整理汇总了C#中System.Management.Automation.ScriptBlock.GetPowerShell方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptBlock.GetPowerShell方法的具体用法?C# ScriptBlock.GetPowerShell怎么用?C# ScriptBlock.GetPowerShell使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.Automation.ScriptBlock的用法示例。


在下文中一共展示了ScriptBlock.GetPowerShell方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateCompatibleLanguageMode

        /// <summary>
        /// Ensures that the provided script block is compatible with the current language mode - to
        /// be used when a script block is being dotted.
        /// </summary>
        /// <param name="scriptBlock">The script block being dotted</param>
        /// <param name="languageMode">The current language mode</param>
        /// <param name="invocationInfo">The invocation info about the command</param>
        protected static void ValidateCompatibleLanguageMode(ScriptBlock scriptBlock,
            PSLanguageMode languageMode,
            InvocationInfo invocationInfo)
        {
            // If we are in a constrained language mode (Core or Restricted), block it.
            // We are currently restricting in one direction:
            //    - Can't dot something from a more permissive mode, since that would probably expose
            //      functions that were never designed to handle untrusted data.
            // This function won't be called for NoLanguage mode so the only direction checked is trusted 
            // (FullLanguage mode) script running in a constrained/restricted session.
            if ((scriptBlock.LanguageMode.HasValue) &&
                (scriptBlock.LanguageMode != languageMode) &&
                ((languageMode == PSLanguageMode.RestrictedLanguage) ||
                (languageMode == PSLanguageMode.ConstrainedLanguage)))
            {
                // Finally check if script block is really just PowerShell commands plus parameters.
                // If so then it is safe to dot source across language mode boundaries.
                bool isSafeToDotSource = false;
                try
                {
                    scriptBlock.GetPowerShell();
                    isSafeToDotSource = true;
                }
                catch (Exception e)
                {
                    CheckForSevereException(e);
                }

                if (!isSafeToDotSource)
                {
                    ErrorRecord errorRecord = new ErrorRecord(
                    new NotSupportedException(
                        DiscoveryExceptions.DotSourceNotSupported),
                        "DotSourceNotSupported",
                        ErrorCategory.InvalidOperation,
                        null);
                    errorRecord.SetInvocationInfo(invocationInfo);
                    throw new CmdletInvocationException(errorRecord);
                }
            }
        }
开发者ID:40a,项目名称:PowerShell,代码行数:48,代码来源:CommandProcessorBase.cs


注:本文中的System.Management.Automation.ScriptBlock.GetPowerShell方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。