Incorrect behaviour of Get-ChildItem cmdlet in case IIS locations [Answered]RSS

2 replies

Last post Oct 10, 2013 09:58 AM by Sergey.terentyev.v

  • Incorrect behaviour of Get-ChildItem cmdlet in case IIS locations

    Oct 02, 2013 10:49 AM|Sergey.terentyev.v|LINK

    My environment:

    OS Windows 7 enterprise: Service Pack 1
    .NET Framework: 4.0.30319.18052
    Powershell version: 3.0
    IIS: 7.5.7600.16385


    I try to execute following scripts from my c# code:

    script1:

    import-module webadministration
    Get-ChildItem iis:\apppools | % { $_.PSObject.TypeNames.Insert(0, "MyCustomName"); $_ }

    script2:

    import-module webadministration
    Get-ChildItem iis:\sites | %{ $_.PSObject.TypeNames.Insert(0, "MyCustomName"); $_ }

    After execution, on C# side, TypeNames property for each result object will be unchanged(without "MyCustomName" name)
    if i execute one of the scripts twice, number of items of TypeNames property for each result object will be incorrect.

    If i use powershell 2.0 the result will be right.

    Could you please provide  a workaround. It's very critical for me

    C# code:

    using System.Collections.Generic;
    using System.Management.Automation;
    using System.Management.Automation.Runspaces;


    namespace ConsoleApplication1
    {

    public class PSCommandProcessor
    {
    private readonly Runspace _runspace;

    public PSCommandProcessor()
    {
    var runspaceConfiguration = RunspaceConfiguration.Create();
    _runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
    _runspace.Open();
    }

    public IEnumerable<PSObject> Execute(string command, params KeyValuePair<string, object>[] arguments)
    {
    var pipeline = _runspace.CreatePipeline();
    var myCommand = new Command(command, true);
    foreach (var argument in arguments)
    {
    myCommand.Parameters.Add(new CommandParameter(argument.Key, argument.Value));
    }
    pipeline.Commands.Add(myCommand);

    return pipeline.Invoke();
    }

    public void Close()
    {
    _runspace.Close();
    }
    }

    class Program
    {
    static void Main()
    {
    var psCmdProcessor = new PSCommandProcessor();
    var result = psCmdProcessor.Execute(Properties.Resources.TextFile1);

    psCmdProcessor.Close();
    }
    }
    }

  • Re: Incorrect behaviour of Get-ChildItem cmdlet in case IIS locations

    Oct 07, 2013 02:59 AM|Angie xu - MSFT|LINK

    Hi Sergey

    Sergey.terentyev.v

    if i execute one of the scripts twice, number of items of TypeNames property for each result object will be incorrect.    If i use powershell 2.0 the result will be right.

    I'm not sure what the root of this issue is,  I think you could give a feedback to Microsoft connect site(http://connect.microsoft.com/ ), Microsoft engineers will evaluate this seriously, and check whether they have good workarounds for you.

    Regards

     

    Angie xu

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: Incorrect behaviour of Get-ChildItem cmdlet in case IIS locations

    Oct 10, 2013 09:58 AM|Sergey.terentyev.v|LINK

    Hi. Thanks for your reply.