Working with Powershell Objects?

I've been looking for an answer to this for a while.

I'm using powershell to return information that I need to work with.  The Script returns a hashtable.  However I can't seem to get to the data in the hashtable.  I'm fairly new to this stuff so I at the end of ideas.  Here's my code.

    string scriptFile = ScriptText.CreatSciptText(@"C:\scripts\ldap\Format-FingerDictionary.ps1");
            Command myCommand = new Command(scriptFile, true);
            int[] znums = new int[] { 115653, 209795, 262160, 243272 };
            CommandParameter commParam = new CommandParameter("Znum", znums);
            myCommand.Parameters.Add(commParam);
            pipeline.Commands.Add(myCommand);
            var obs = pipeline.Invoke();
            Hashtable hash = (Hashtable)obs[0].BaseObject;
            foreach (DictionaryEntry entry in hash)
            {
                var theKey = entry.Key;
                var theValue = entry.Value;
                Console.WriteLine(@"Key: {0} Value:{1}", theKey., theValue);
            }

When I loop through the hashtable all I get is System.Object[] as the type for both the key and the value.  The key should be an integer, and the value should be an array or list (I'm not quite sure how the powershell array would transfer t

June 26th, 2013 7:09pm

Hi,

Based on your description, Im afraid that it is not the correct forum for this issue, since this forum is to discuss: Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor. I am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right forum.

If this issue is related to PowerShell, you could post this issue to Windows PowerShell forum for better support.

Best Regards,

Free Windows Admin Tool Kit Click here and download it now
June 27th, 2013 9:20am

I'd ask in the C# Language forum.

I'd also read "'Short but complete programs' by Jon Skeet.

I cannot figure out where "ScriptText.CreatSciptText" coms from, so I cannot compile and test your code....

June 27th, 2013 4:53pm

Hi,

Just checking in to see if the suggestions were helpful. Please let us know if you would like further assistance.

 

If you have any feedback on our support, please click here .

Free Windows Admin Tool Kit Click here and download it now
July 1st, 2013 10:26am

Sorry, that a static class that I wrote that writes the script from a file.

After banging my head on this, and even hoping that asking this question might get some help.  I decided to go another way.

I was actually testing two way of solving this, the first was to simply return an array of information on an individual user.  I was able to get the information out of that, but it was also returned as an array of PSObjects.  I was hoping that with this I would be able to feed an array of names and get a Dictionary back.  I do get the hashtable back, but I can't figure out how to get the data out of the PSObjects in the hashtable.  I was hoping I could get an object back that I could use LINQ on, but it looks like a hashtable doesn't implement IEnumerable, so I have to convert it into a Dictionary. 

So I'm just moving on.  Thanks for everyone's help.

July 1st, 2013 5:54pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics