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, }
LVL 1
amaru96Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.