I’m trying to export the result of a WMI query to CSV. It results in Sytem.Object<\/span> or blank when I’ve tried to apply different solutions from the web.<\/p>\n
$ComputerName = Get-Content c:\\Scripts\\eCW\\Computers.txt The insert Code wasn’t working<\/p>","upvoteCount":2,"answerCount":15,"datePublished":"2018-02-16T21:13:04.000Z","author":{"@type":"Person","name":"mikewilson9290","url":"https://community.spiceworks.com/u/mikewilson9290"},"acceptedAnswer":{"@type":"Answer","text":" so if you have a variable, $foo that contains an object, just do<\/p>\n To get a aproperty from an expression<\/p>\n I am assuming you have made changes to the original post - and I can’t work out what you are trying and, specifically, what output you get.<\/p>\n And PLEASE use the </><\/strong> tool in the editor tool bar enter code and results - that way it’s easier to read (and you are more likely to get better answers if we can read the code easily)/<\/p>","upvoteCount":1,"datePublished":"2018-02-21T14:46:14.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/13","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}},"suggestedAnswer":[{"@type":"Answer","text":" I’m trying to export the result of a WMI query to CSV. It results in Sytem.Object<\/span> or blank when I’ve tried to apply different solutions from the web.<\/p>\n $ComputerName = Get-Content c:\\Scripts\\eCW\\Computers.txt The insert Code wasn’t working<\/p>","upvoteCount":2,"datePublished":"2018-02-16T21:13:04.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/1","author":{"@type":"Person","name":"mikewilson9290","url":"https://community.spiceworks.com/u/mikewilson9290"}},{"@type":"Answer","text":" What is the code you use to export?<\/p>\n If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n Post code button wasn’t working for me. I edited the post and added the code.<\/p>","upvoteCount":0,"datePublished":"2018-02-16T22:09:39.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/3","author":{"@type":"Person","name":"mikewilson9290","url":"https://community.spiceworks.com/u/mikewilson9290"}},{"@type":"Answer","text":" why wmi , do not use wmi to query programs installed, its slow and re-configures all apps.<\/p>\n better use https://gallery.technet.microsoft.com/scriptcenter/Get-RemoteProgram-Get-list-de9fd2b4<\/a><\/p>\n I do not know of what you speak. Reconfigure?!?! What am I doing to my computers? I’ll have to look into that script on Tuesday when I get back into the office. Looks promising.<\/p>","upvoteCount":0,"datePublished":"2018-02-16T22:22:29.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/5","author":{"@type":"Person","name":"mikewilson9290","url":"https://community.spiceworks.com/u/mikewilson9290"}},{"@type":"Answer","text":" Querying win32_product can cause problems on systems. More here (2nd para): Why Win32_Product is Bad News! - SDM Software<\/a><\/p>\n That script Jiten linked to is probably a better option.<\/p>","upvoteCount":2,"datePublished":"2018-02-16T22:34:38.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/6","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}},{"@type":"Answer","text":" The Win32_product class us well known for being problematic. Sadly, Msft has not offered a reasonable alternative<\/p>","upvoteCount":0,"datePublished":"2018-02-17T11:55:39.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/7","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}},{"@type":"Answer","text":" So I’ve integrated the Get-RemoteProgram module into my script. (got a little schooling there in Powershell modules in the process…Thanks!) However, I still have the same issue. Something about using a variable for the command and trying to output that to the $Props object all in the $PCData object, somewhere in there it is only getting System.Object<\/span>. That is still coming out on the CSV. Oh, and it now starts on the 22 row ; )<\/p>\n Here is the replacement for the line above (I tried with and without -excludesimlar with same result):<\/p>\n $App = Get-RemoteProgram -Computername $PC -ExcludeSimilar | Where{$_.ProgramName -Like ‘Citrix*’}<\/p>","upvoteCount":0,"datePublished":"2018-02-20T21:58:10.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/8","author":{"@type":"Person","name":"mikewilson9290","url":"https://community.spiceworks.com/u/mikewilson9290"}},{"@type":"Answer","text":" That issue sounds like you are trying to write the entire objet, not individual properties.<\/p>\n What does:<\/p>\n Show?<\/p>\n In general - you need to look ‘back’ - what is the data you are sending to the CSV. I suspect you need to remove some properties to get them into the CSV. This is where simple PowerShell Debugging comes into play.<\/p>","upvoteCount":1,"datePublished":"2018-02-21T11:16:45.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/9","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}},{"@type":"Answer","text":" Good call tfl. I isolated that and Get-RemoteProgram outputs a table. I have tried to break it down to just the one program, but it still outputs the table:<\/p>\n I’m working on extracting the text from the string or figuring out where to edit the Get-RemoteProgram to only send the one item<\/p>\n PS> Get-RemoteProgram -ExcludeSimilar -SimilarWord 1 | Where{$_.ProgramName -Like ‘Citrix*’}<\/p>\n PS> Get-RemoteProgram -ExcludeSimilar -SimilarWord 1 | Where{$_.ProgramName -Like ‘Citrix*’} Citrix Receiver 4.9 MyHostname<\/p>","upvoteCount":0,"datePublished":"2018-02-21T14:34:57.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/10","author":{"@type":"Person","name":"mikewilson9290","url":"https://community.spiceworks.com/u/mikewilson9290"}},{"@type":"Answer","text":" That is correct. You are retrieving an object that has two properties.<\/p>","upvoteCount":0,"datePublished":"2018-02-21T14:38:11.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/11","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}},{"@type":"Answer","text":" Any suggestion on extracting just the one property?<\/p>\n (BTW I’m having a heck of a time with entering code into my post and the formatting in my posts. I tried to find a tutorial, but…)<\/p>","upvoteCount":0,"datePublished":"2018-02-21T14:41:46.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/12","author":{"@type":"Person","name":"mikewilson9290","url":"https://community.spiceworks.com/u/mikewilson9290"}},{"@type":"Answer","text":" I should have known that. I’ve used that in other scripts and didn’t make the connection. Thanks for the heads up. Been learning PowerShell over the last year by hacking together scripts I find on the internet.<\/p>","upvoteCount":0,"datePublished":"2018-02-21T15:34:48.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/14","author":{"@type":"Person","name":"mikewilson9290","url":"https://community.spiceworks.com/u/mikewilson9290"}},{"@type":"Answer","text":" Here is the final code I came up with for this. Thanks to everyone who contributed.<\/p>\n still couldn’t get the </> button to work for me (comes up blank when I enter code and submit the post)<\/p>\n <# .Notes
\n$PCData = foreach ($PC in $ComputerName) {
\nIf (Test-Connection -ComputerName $PC -Count 2 -Quiet) {
\nWrite-Verbose “Checking software on $PC” -Verbose
\n$App = Get-WmiObject -Class Win32_Product | where { $_.Name -match “Citrix”}
\n$Props = @{
\nComputerName = $PC
\nStatus = “Online”
\nCitrixInstalled = $App
\n}
\nNew-Object -TypeName PSObject -Property $Props
\n}
\nElse {
\nWrite-Verbose “$PC Offline” -Verbose
\n$Props = @{
\nComputerName = $PC
\nStatus = “No Response”
\nCitrixInstalled = ‘’
\n}
\nNew-Object -TypeName PSObject -Property $Props
\n}
\n}
\nWrite-Verbose “Creating Report” -Verbose
\nWrite-Output $PCData | select ComputerName, Status, CitrixInstalled | Export-CSV c:\\Scripts\\eCW\\ComputerRpt1.csv -NoTypeInformation
\nWrite-Verbose “Report Complete” -Verbose<\/p>\n
$foo.property\n<\/code><\/pre>\n
(Get-ChildItem c:\\ -file | select -last 1).fullname\n<\/code><\/pre>\n
\n$PCData = foreach ($PC in $ComputerName) {
\nIf (Test-Connection -ComputerName $PC -Count 2 -Quiet) {
\nWrite-Verbose “Checking software on $PC” -Verbose
\n$App = Get-WmiObject -Class Win32_Product | where { $_.Name -match “Citrix”}
\n$Props = @{
\nComputerName = $PC
\nStatus = “Online”
\nCitrixInstalled = $App
\n}
\nNew-Object -TypeName PSObject -Property $Props
\n}
\nElse {
\nWrite-Verbose “$PC Offline” -Verbose
\n$Props = @{
\nComputerName = $PC
\nStatus = “No Response”
\nCitrixInstalled = ‘’
\n}
\nNew-Object -TypeName PSObject -Property $Props
\n}
\n}
\nWrite-Verbose “Creating Report” -Verbose
\nWrite-Output $PCData | select ComputerName, Status, CitrixInstalled | Export-CSV c:\\Scripts\\eCW\\ComputerRpt1.csv -NoTypeInformation
\nWrite-Verbose “Report Complete” -Verbose<\/p>\nget-wmiobject <#query#> |\nexport-csv \"c:\\file.csv\" -notypeinformation\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2018-02-16T21:23:38.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
\nEdited: I missed csv in export csv<\/p>\ngc C:\\computers.txt |Foreach{Get-RemoteProgram -ComputerName $_ |where{$_.ProgramName -like '*Citrix*' |export-csv c:\\citrix.csv -notype}}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2018-02-16T22:13:41.000Z","url":"https://community.spiceworks.com/t/system-object-variable-to-csv/635450/4","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},{"@type":"Answer","text":"
Write-Output $PCData | select ComputerName, Status, CitrixInstalled\n<\/code><\/pre>\n
\nProgramName ComputerName<\/p>\n
\n
\n.Synopsis
\nGenerates a list of computers and exports to CSV with version of program installed<\/p>\n
\nAuthor : Mike Wilson
\nDate Created : 2/21/18
\n#><\/p>\n<\/a>empty the Computername variable for running in same window<\/h1>\n