Hi everyone,
I am experimenting a little bit with Hashtables in PowerShell v2 and v3 and v4. I am asking for your help in regards of exporting multiple values to a CSV-file. Here’s what I’m trying:
Get the status of the Windows Defender Service via WMI:
If I try exporting the Hashtable to CSV I always end up with a “System.Object” in the column where those multiple values are stored. Below is what I’ve tried so far
You can turn it into an object using pscustomobject, and then successfully pipe that to a Csv. Notice, I’ve also created a separate keys for process, state, and startmode. I’m not sure if this will work (for you), so if not, take a look at the second option to leave the process, state, and startmode as a single value for the one, WindowsDefender, key.
Anyway, let me know if this helps, and if you can’t scroll left-right in the script windows, use the double-sided arrows to open it in a separate window.
Hey sir,
thank you very much! Both approaches work with PowerShell v3. Unfortunately I didn’t get them to work with PowerShell v2. The output I get is:
That’s expected behavior prior to PowerShell 3.0, when creating a custom object with this option. There’s different ways to create custom objects in the earlier versions of PowerShell. Here’s how to do it in the different versions: http://blogs.technet.com/b/heyscriptingguy/archive/2013/11/07/a-powershell-object-lesson-part-3.aspx. I choose PowerShell 3.0, since I think that’s when we were able to order our hash tables, such as what you did in your example.
Hi Tim,
thanks, but my goal was just to play around with Hashtables, therefore I used it With Tommy’s help I now figured out that for outputting stuff to a CSV-File a custom PSObject is better choice than a Hashtable.So I learned two things in one catch. Looks like a good day from my perspective