Example #1
0
 internal RemoteHelpInfo(
     ExecutionContext context,
     RemoteRunspace remoteRunspace,
     string remoteHelpTopic,
     string remoteHelpCategory,
     HelpCategory localHelpCategory)
     : base(localHelpCategory)
 {
     using (System.Management.Automation.PowerShell powerShell = System.Management.Automation.PowerShell.Create())
     {
         powerShell.AddCommand("Get-Help");
         powerShell.AddParameter("Name", (object)remoteHelpTopic);
         if (!string.IsNullOrEmpty(remoteHelpCategory))
         {
             powerShell.AddParameter("Category", (object)remoteHelpCategory);
         }
         powerShell.Runspace = (Runspace)remoteRunspace;
         Collection <PSObject> collection;
         using (new PowerShellStopper(context, powerShell))
         {
             using (RemoteHelpInfo.tracer.TraceScope("Downloading remote help for {0}", (object)remoteHelpTopic))
                 collection = powerShell.Invoke();
         }
         this.deserializedRemoteHelp = collection != null && collection.Count != 0 ? collection[0] : throw new HelpNotFoundException(remoteHelpTopic);
         this.deserializedRemoteHelp.TypeNames.Clear();
         this.deserializedRemoteHelp.TypeNames.Add("MamlCommandHelpInfo");
         this.deserializedRemoteHelp.TypeNames.Add("HelpInfo");
         this.deserializedRemoteHelp.Methods.Remove("ToString");
     }
 }
Example #2
0
        public AbstractCmdletTest()
        {
            _pwrSh = System.Management.Automation.PowerShell.Create();
            // Import Module
            _pwrSh.AddCommand("import-module");
            _pwrSh.AddParameter("Name", "./Sentral.Api.PowerShell.dll");
            _pwrSh.Invoke();
            _pwrSh.Commands.Clear();


            var settings = TestSettings.LoadSettings();

            try
            {
                ConnectSentralApi.GetSentralAPIConnection();
            }
            catch
            {
                var connection = new ConnectSentralApi()
                {
                    BaseUrl    = settings.BaseUrl,
                    ApiKey     = settings.ApiKey,
                    TenantCode = settings.ApiTenant
                };

                var enumerator = connection.Invoke().GetEnumerator();

                while (enumerator.MoveNext())
                {
                }
            }


            _isTestSite = settings.BaseUrl.Contains(".sentral.school/");
        }
 /// <summary>
 /// Takes script text as input and runs it
 /// </summary>
 /// <param name="scriptText"></param>
 private void RunScript(string scriptText)
 {
     using (System.Management.Automation.PowerShell powerShell = System.Management.Automation.PowerShell.Create())
     {
         powerShell.Commands.AddScript(scriptText);
         powerShell.AddParameter("serverName", ConfigurationManager.AppSettings["serverName"]);
         powerShell.AddParameter("batchName", ConfigurationManager.AppSettings["batchName"]);
         powerShell.AddParameter("batchParams", ConfigurationManager.AppSettings["batchParams"]);
         try
         {
             powerShell.Invoke();
         }
         catch (Exception exp)
         {
             throw exp;
         }
     }
 }
Example #4
0
        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (GetIsComputerNameSpecified(context))
            {
                targetCommand.AddParameter("ComputerName", PSComputerName.Get(context));
            }

            if (Authentication.Expression != null)
            {
                targetCommand.AddParameter("Authentication", Authentication.Get(context));
            }

            if (Credential.Expression != null)
            {
                targetCommand.AddParameter("Credential", Credential.Get(context));
            }

            if (CertificateThumbprint.Expression != null)
            {
                targetCommand.AddParameter("CertificateThumbprint", CertificateThumbprint.Get(context));
            }

            if (Name.Expression != null)
            {
                targetCommand.AddParameter("Name", Name.Get(context));
            }

            if (OperationTimeoutSec.Expression != null)
            {
                targetCommand.AddParameter("OperationTimeoutSec", OperationTimeoutSec.Get(context));
            }

            if (Port.Expression != null)
            {
                targetCommand.AddParameter("Port", Port.Get(context));
            }

            if (SessionOption.Expression != null)
            {
                targetCommand.AddParameter("SessionOption", SessionOption.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
        // Additional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (Namespace.Expression != null)
            {
                targetCommand.AddParameter("Namespace", Namespace.Get(context));
            }

            if (OperationTimeoutSec.Expression != null)
            {
                targetCommand.AddParameter("OperationTimeoutSec", OperationTimeoutSec.Get(context));
            }

            if (InputObject.Expression != null)
            {
                targetCommand.AddParameter("InputObject", InputObject.Get(context));
            }

            if (Query.Expression != null)
            {
                targetCommand.AddParameter("Query", Query.Get(context));
            }

            if (QueryDialect.Expression != null)
            {
                targetCommand.AddParameter("QueryDialect", QueryDialect.Get(context));
            }

            if (Property.Expression != null)
            {
                targetCommand.AddParameter("Property", Property.Get(context));
            }

            if (PassThru.Expression != null)
            {
                targetCommand.AddParameter("PassThru", PassThru.Get(context));
            }

            if (ResourceUri != null)
            {
                targetCommand.AddParameter("ResourceUri", ResourceUri.Get(context));
            }

            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
Example #6
0
        // Module defining this command


        // Additional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (UICulture.Expression != null)
            {
                targetCommand.AddParameter("UICulture", UICulture.Get(context));
            }

            if (BaseDirectory.Expression != null)
            {
                targetCommand.AddParameter("BaseDirectory", BaseDirectory.Get(context));
            }
            //If BaseDirectory is not specified, try to use the workflow base directory.
            else
            {
                throw new ArgumentException(GeneratedActivitiesResources.ImportLocalizedDataWithEmptyEmptyorNullBaseDirectory);
            }

            if (FileName.Expression != null)
            {
                targetCommand.AddParameter("FileName", FileName.Get(context));
            }

            if (SupportedCommand.Expression != null)
            {
                targetCommand.AddParameter("SupportedCommand", SupportedCommand.Get(context));
            }

            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
        /// <summary>
        /// Process markdown as path.
        /// </summary>
        /// <param name="parameter">Name of parameter to pass to `ConvertFrom-Markdown`.</param>
        /// <param name="input">Value of parameter.</param>
        private void ConvertFromMarkdown(string parameter, object input)
        {
            _powerShell.AddCommand("Microsoft.PowerShell.Utility\\ConvertFrom-Markdown").AddParameter(parameter, input);
            if (!UseBrowser)
            {
                _powerShell.AddParameter("AsVT100EncodedString");
            }

            Collection <MarkdownInfo> output = _powerShell.Invoke <MarkdownInfo>();

            if (_powerShell.HadErrors)
            {
                foreach (ErrorRecord errorRecord in _powerShell.Streams.Error)
                {
                    WriteError(errorRecord);
                }
            }

            foreach (MarkdownInfo result in output)
            {
                ProcessMarkdownInfo(result);
            }
        }
Example #8
0
        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments
            // Specified ClassName cannot be WhiteSpace or NULL
            //
            if (ClassName.Expression != null && !string.IsNullOrWhiteSpace(ClassName.Get(context)))
            {
                targetCommand.AddParameter("ClassName", ClassName.Get(context));
            }

            if (Namespace.Expression != null)
            {
                targetCommand.AddParameter("Namespace", Namespace.Get(context));
            }

            if (OperationTimeoutSec.Expression != null)
            {
                targetCommand.AddParameter("OperationTimeoutSec", OperationTimeoutSec.Get(context));
            }

            if (MethodName.Expression != null)
            {
                targetCommand.AddParameter("MethodName", MethodName.Get(context));
            }

            if (PropertyName.Expression != null)
            {
                targetCommand.AddParameter("PropertyName", PropertyName.Get(context));
            }

            if (QualifierName.Expression != null)
            {
                targetCommand.AddParameter("QualifierName", QualifierName.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (NoEncryption.Expression != null)
            {
                targetCommand.AddParameter("NoEncryption", NoEncryption.Get(context));
            }

            if (CertificateCACheck.Expression != null)
            {
                targetCommand.AddParameter("CertificateCACheck", CertificateCACheck.Get(context));
            }

            if (CertificateCNCheck.Expression != null)
            {
                targetCommand.AddParameter("CertificateCNCheck", CertificateCNCheck.Get(context));
            }

            if (CertRevocationCheck.Expression != null)
            {
                targetCommand.AddParameter("CertRevocationCheck", CertRevocationCheck.Get(context));
            }

            if (EncodePortInServicePrincipalName.Expression != null)
            {
                targetCommand.AddParameter("EncodePortInServicePrincipalName", EncodePortInServicePrincipalName.Get(context));
            }

            if (Encoding.Expression != null)
            {
                targetCommand.AddParameter("Encoding", Encoding.Get(context));
            }

            if (HttpPrefix.Expression != null)
            {
                targetCommand.AddParameter("HttpPrefix", HttpPrefix.Get(context));
            }

            if (MaxEnvelopeSizeKB.Expression != null)
            {
                targetCommand.AddParameter("MaxEnvelopeSizeKB", MaxEnvelopeSizeKB.Get(context));
            }

            if (ProxyAuthentication.Expression != null)
            {
                targetCommand.AddParameter("ProxyAuthentication", ProxyAuthentication.Get(context));
            }

            if (ProxyCertificateThumbprint.Expression != null)
            {
                targetCommand.AddParameter("ProxyCertificateThumbprint", ProxyCertificateThumbprint.Get(context));
            }

            if (ProxyCredential.Expression != null)
            {
                targetCommand.AddParameter("ProxyCredential", ProxyCredential.Get(context));
            }

            if (ProxyType.Expression != null)
            {
                targetCommand.AddParameter("ProxyType", ProxyType.Get(context));
            }

            if (UseSsl.Expression != null)
            {
                targetCommand.AddParameter("UseSsl", UseSsl.Get(context));
            }

            if (Impersonation.Expression != null)
            {
                targetCommand.AddParameter("Impersonation", Impersonation.Get(context));
            }

            if (PacketIntegrity.Expression != null)
            {
                targetCommand.AddParameter("PacketIntegrity", PacketIntegrity.Get(context));
            }

            if (PacketPrivacy.Expression != null)
            {
                targetCommand.AddParameter("PacketPrivacy", PacketPrivacy.Get(context));
            }

            if (Protocol.Expression != null)
            {
                targetCommand.AddParameter("Protocol", Protocol.Get(context));
            }

            if (UICulture.Expression != null)
            {
                targetCommand.AddParameter("UICulture", UICulture.Get(context));
            }

            if (Culture.Expression != null)
            {
                targetCommand.AddParameter("Culture", Culture.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (ClassName.Expression != null)
            {
                targetCommand.AddParameter("ClassName", ClassName.Get(context));
            }

            if (Key.Expression != null)
            {
                targetCommand.AddParameter("Key", Key.Get(context));
            }

            if (CimClass.Expression != null)
            {
                targetCommand.AddParameter("CimClass", CimClass.Get(context));
            }

            if (Property.Expression != null)
            {
                targetCommand.AddParameter("Property", Property.Get(context));
            }

            if (Namespace.Expression != null)
            {
                targetCommand.AddParameter("Namespace", Namespace.Get(context));
            }

            if (OperationTimeoutSec.Expression != null)
            {
                targetCommand.AddParameter("OperationTimeoutSec", OperationTimeoutSec.Get(context));
            }

            if (ResourceUri != null)
            {
                targetCommand.AddParameter("ResourceUri", ResourceUri.Get(context));
            }

            if (ClientOnly.Expression != null)
            {
                // Retrieve our host overrides
                var      hostValues   = context.GetExtension <HostParameterDefaults>();
                string[] computerName = null;

                if (hostValues != null)
                {
                    Dictionary <string, object> incomingArguments = hostValues.Parameters;
                    if (incomingArguments.ContainsKey("PSComputerName"))
                    {
                        computerName = incomingArguments["PSComputerName"] as string[];
                    }
                }

                if (computerName == null)
                {
                    targetCommand.AddParameter("ClientOnly", ClientOnly.Get(context));
                }
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }