Having trouble adding quotes to the values of “Select-Object”.

I have a rather, what seems to be simple, issue on my hands. When running a Get-WMIObject command piping to a Select-Object stating the properties to be selected, some of the values have commas in them. For example

Get-WMIObject -ComputerName $env:ComputerName Win32_Product | Select-Object Name, Version, Vendor, InstallDate

This returns all of the desired data as I need it but when exported later in the script, the “Vendor” could have a comma in their name (VMware, Inc.) and that comma wrecks that line. See below as an example:

Name Version Vendor InstallDate text
Windows SDK Facade Windows WinMD Versioned 10.1.15063.0 Microsoft Corporation 20170908
VMware vSphere Client 6.0 6.0.0.5505 VMware Inc. 20170908
Microsoft Visual C++ 2008 Redistributable – x86 9.0.30729.4148 9.0.30729.4148 Microsoft Corporation 20170908

My thought is to wrap each value into quotes but I am failing to figure this out, I have created an abomination like below with still no luck:

$ListOfPrinters = Get-WmiObject -ComputerName $env:Computername Win32_Printer $printers = @() Foreach ($printer in $ListOfPrinters ){ $Details = "" | Select-Object Name,Location $Details.Name = "$Printer.Name" $Details.Location = "$Printer.Location" $Printers += $Details } $MyReport += Get-CustomFunction ($Printers) 

At the end of everything, this report will be ingested by another system that will parse the value directly as a CSV. Any and all help, or a point in the right direction would be appreciated.

submitted by /u/exaltedgod
[link] [comments]

Leave a Reply