• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1177
  • Last Modified:

Powershell export showing "System.String[]" instead of the result.

Hi guys, I'm running an SCCM cmdlet to get some info around updates and most of the resulting export is OK, however one column shows "System.String[]" instead of the result. I believe this has to do with the contents of that specific field which looks like: {Updates, Windows7, Windows Server 2008 R2, }

The command I'm running is:
Get-CMSoftwareUpdate | Select-Object ArticleID, BulletinID, CI_ID, IsEnabled, IsExpired, IsSuperseded, LocalizedDescription, LocalizedCategoryInstanceNames, LocalizedDisplayName, LocalizedInformativeURL | Export-Csv c:\temp\test.csv

The result:
Export.pngWhat I'd like it to do is read the first value in the "LocalizedCategoryInstanceNames" field and make it a new column called "Update Type". Then any other entry in the next column called "OS". Something like this:
Export2.pngPlease note that the LocalizedCategoryInstanceNames may contain any number of entries:
{Updates, Windows 7, }
{Security Updates, Windows 7, Windows Server 2008 R2, }
{Security Updates, Windows 7,  Datacenter Edition, Windows Server 2008 R2, }
0
amaru96
Asked:
amaru96
  • 5
  • 4
1 Solution
 
RobSampsonCommented:
Hi, you should be able to use a calculated property to get the array elements.  The System.String[] is an array of strings.

Get-CMSoftwareUpdate | Select-Object ArticleID, BulletinID, CI_ID, IsEnabled, IsExpired, IsSuperseded, LocalizedDescription, LocalizedCategoryInstanceNames, @{n='Update Type';e={LocalizedDisplayName[0]}}, @{n='OS';e={LocalizedDisplayName[1]}}, LocalizedInformativeURL | Export-Csv c:\temp\test.csv

Open in new window


Rob.
0
 
amaru96Author Commented:
I tried that but still get System.String[] appearing under the LocalizedCategoryInstanceNames column. The only change is that 2 new columns have appeared (Update Type and OS) but are blank.
0
 
RobSampsonCommented:
Oops, typo....try this
Get-CMSoftwareUpdate | Select-Object ArticleID, BulletinID, CI_ID, IsEnabled, IsExpired, IsSuperseded, LocalizedDescription, @{n='Update Type';e={LocalizedCategoryInstanceNames[0]}}, @{n='OS';e={LocalizedCategoryInstanceNames[1]}}, LocalizedDisplayName, LocalizedInformativeURL | Export-Csv c:\temp\test.csv

Open in new window

0
On-Demand: Securing Your Wi-Fi for Summer Travel

Traveling this summer?Check out our on-demand webinar to learn about the importance of Wi-Fi security and 3 easy measures you can start taking immediately to protect your private data while using public Wi-Fi. Follow us today to learn more!

 
amaru96Author Commented:
Now LocalizedCategoryInstanceNames  is gone, but "Update Type" and "OS" columns are still blank.
0
 
RobSampsonCommented:
Oh, I was missing the $_. from the calculated expression.

Get-CMSoftwareUpdate | Select-Object ArticleID, BulletinID, CI_ID, IsEnabled, IsExpired, IsSuperseded, LocalizedDescription, @{n='Update Type';e={$_.LocalizedCategoryInstanceNames[0]}}, @{n='OS';e={$_.LocalizedCategoryInstanceNames[1]}}, LocalizedDisplayName, LocalizedInformativeURL | Export-Csv c:\temp\test.csv

Open in new window


Rob.
0
 
amaru96Author Commented:
Getting close :-)

The "Update Type" looks great. However, the "OS" only shows the first value.

For example, {Security Updates, Windows 7,  Datacenter Edition, Windows Server 2008 R2, } shows:
Update Type: Security Updates
OS: Windows 7

The rest of the items are discarded.
Export3.png
Appreciate your help.
0
 
RobSampsonCommented:
Ah, OK, so to put all of the other elements into the OS field, we use the range operator to get the "rest" of the array.

So instead of
@{n='OS';e={$_.LocalizedCategoryInstanceNames[1]}}

we use
@{n='OS';e={$_.LocalizedCategoryInstanceNames[1 .. ($_.LocalizedCategoryInstanceNames.count-1)] -join ","}}

Get-CMSoftwareUpdate | Select-Object ArticleID, BulletinID, CI_ID, IsEnabled, IsExpired, IsSuperseded, LocalizedDescription, @{n='Update Type';e={$_.LocalizedCategoryInstanceNames[0]}}, @{n='OS';e={$_.LocalizedCategoryInstanceNames[1 .. ($_.LocalizedCategoryInstanceNames.count-1)] -join ","}}, LocalizedDisplayName, LocalizedInformativeURL | Export-Csv c:\temp\test.csv

Open in new window


Regards,

Rob.
0
 
amaru96Author Commented:
That works great, thanks Rob. Really appreciate your help.
0
 
RobSampsonCommented:
Awesome.  Thanks for the grade.

Arrays are relatively easy to work with in Powershell compared to some other languages ;-)

Rob.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now