src/Microsoft.PowerShell.Activities/Activities/WmiActivities.cs
/// <summary>
/// Implements the logic of this activity
/// </summary>
/// <param name="context">The activity context to refer to</param>
Implements the logic of this activity
Implements the logic of this activity
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell command;
            command = GetWmiCommandCore(context, "Invoke-WmiMethod");
            if (!String.IsNullOrEmpty(Path.Get(context)))
            {
                command.AddParameter("Path", Path.Get(context));
                Tracer.WriteMessage(String.Format(CultureInfo.InvariantCulture, "PowerShell activity ID={0}: Setting parameter {1} to {2}.",
                    context.ActivityInstanceId, "Path", Path.Get(context)));
            }
            if (!String.IsNullOrEmpty(Class.Get(context)))
            {
                command.AddParameter("Class", Class.Get(context));
                Tracer.WriteMessage(String.Format(CultureInfo.InvariantCulture, "PowerShell activity ID={0}: Setting parameter {1} to {2}.",
                    context.ActivityInstanceId, "Class", Class.Get(context)));
            }
            if (!String.IsNullOrEmpty(Name.Get(context)))
            {
                command.AddParameter("Name", Name.Get(context));
                Tracer.WriteMessage(String.Format(CultureInfo.InvariantCulture,
                    "PowerShell activity ID={0}: Setting parameter {1} to {2}.",
                        context.ActivityInstanceId, "Name", Name.Get(context)));
            }
            if (ArgumentList.Get(context) != null)
            {
                Collection<PSObject> argCollection = ArgumentList.Get(context).ReadAll();
                if (argCollection.Count > 0)
                {
                    command.AddParameter("ArgumentList", argCollection);
                    Tracer.WriteMessage(String.Format(CultureInfo.InvariantCulture,
                        "PowerShell activity ID={0}: Setting parameter {1} to '{2}'.",
                            context.ActivityInstanceId, "ArgumentList", string.Join("','", argCollection)));
                }
            }
            return new ActivityImplementationContext() { PowerShellInstance = command };
        }
[ System . Diagnostics . CodeAnalysis . SuppressMessage ( " " , " " ) ] protected override ActivityImplementationContext GetPowerShell ( NativeActivityContext context ) { System . Management . Automation . PowerShell command ; command = GetWmiCommandCore ( context , " " ) ; if ( ! String . IsNullOrEmpty ( Path . Get ( context ) ) ) { command . AddParameter ( " " , Path . Get ( context ) ) ; Tracer . WriteMessage ( String . Format ( CultureInfo . InvariantCulture , " " , context . ActivityInstanceId , " " , Path . Get ( context ) ) ) ; } if ( ! String . IsNullOrEmpty ( Class . Get ( context ) ) ) { command . AddParameter ( " " , Class . Get ( context ) ) ; Tracer . WriteMessage ( String . Format ( CultureInfo . InvariantCulture , " " , context . ActivityInstanceId , " " , Class . Get ( context ) ) ) ; } if ( ! String . IsNullOrEmpty ( Name . Get ( context ) ) ) { command . AddParameter ( " " , Name . Get ( context ) ) ; Tracer . WriteMessage ( String . Format ( CultureInfo . InvariantCulture , " " , context . ActivityInstanceId , " " , Name . Get ( context ) ) ) ; } if ( ArgumentList . Get ( context ) != null ) { Collection < PSObject > argCollection = ArgumentList . Get ( context ) . ReadAll ( ) ; if ( argCollection . Count > 0 ) { command . AddParameter ( " " , argCollection ) ; Tracer . WriteMessage ( String . Format ( CultureInfo . InvariantCulture , " " , context . ActivityInstanceId , " " , string . Join ( " " , argCollection ) ) ) ; } } return new ActivityImplementationContext ( ) { PowerShellInstance = command } ; }
Implements the logic of this activity
Implements the logic of this activity
context
NativeActivityContext
The activity context to refer to
The activity context to refer to