Issue Getting Data from File and Using in Script

Here is what I got trying to put together a script to read the patches on a remote PC:

$computer = gc env:computername
$computers= get-content -path c:\computer.txt
$csvfile = "c:\name.csv"
foreach ($computer in $computers) {Get-WmiObject -Class WIN32_QuickFixEngineering | Select-Object "Caption","CSName","Description","InstalledBy","InstalledOn" |ConvertTo-HTML | Out-File $csvfile}

I do get the results, but I get them from the local machine and not the remote one. What am I doing wrong trying to get the computer name from the c:\computer.txt file?

Thanks again for the help.

September 1st, 2015 7:48am

You need to use the -ComputerName parameter of Get-WmiObject.

http://ss64.com/ps/get-wmiobject.html

Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 7:58am

Tried something like this:

$computer = Get-Content "C:\computer.txt"
$csvfile = "c:\name.csv"
Get-WmiObject -Class WIN32_QuickFixEngineering -ComputerName $computer | Select-Object "CSName","Caption","Description","InstalledBy","InstalledOn" |ConvertTo-HTML | Out-File $csvfile

What other way can I make it work?

September 1st, 2015 8:06am

Why are you using ConvertTo-HTML if you're outputting to a CSV file?

Here's something you can play with:

Get-WmiObject Win32_QuickFixEngineering -ComputerName (Get-Content .\computerList.txt) |
    Select CSName,HotFixID,Caption,Description,InstalledBy,InstalledOn |
        Export-Csv .\output.csv -NoTypeInformation

Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 8:54am

This is a funny thread.  All at once there are people with zero computer knowledge trying to write scripts.  It leads to some very funny threads.

Its good.  Curiosity is good.

September 1st, 2015 9:12am

Just a typo.
Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 9:13am

Hey - my whole life is a typo. So what.  As the Bard says, "Humans are ne'er perfect".
September 1st, 2015 10:00am

Thanks, Mike. Your help got me on the right track and I got my scripts working.

@jrv - if you are not ready to offer any assistance, why bother posting? Is computer knowledge ONLY about PoSh?

Free Windows Admin Tool Kit Click here and download it now
September 2nd, 2015 3:46am

If you were the one who wrote the original code you would probably understand why it was so funny, I also cannot understand why people who should know better insist on typing everything on one line. It is like a run-on sentence and is impossible to read or understand.

If you had typed in correctly you would have seen your error immediately. 

It is just so common that it is very funny.  Try formatting your code in a readable way and you will find it easier to see errors.

Computer knowledge is not about PosH but it is a requirement for using PowerShell although you can just use PowerShell to draw pictures and add numbers without any computer knowledge at all.

What I WMI? How does it work?  Where did it come from?  Why is it fundamental to computers?

September 2nd, 2015 4:11am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics