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:49am

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:59am

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:07am

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:55am

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:13am

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

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

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

Other recent topics Other recent topics