I have a command line that I’ve been working on to get data from event logs across multiple remote PC’s. My command works when I list the computer names out, but it does not work if I try to put them in a variable and try to run it using the variable instead of the machine names.
Here is the working code:
get-eventlog -ComputerName PTLW2TYFLK1WIT, PTLL95S7YY1, PTLWC56MXV1WIT -logname Application | select -Property MachineName, TimeWritten, EventID, Source, Message | Where-Object Source -EQ MsiInstaller |sort -Property MachineName, TimeWritten -Descending | ConvertTo-Html | out-file c:\temp\systemlog.htm
But if I try to put those 3 machines into variable $machine and replace the three machine names in the code with the $machine variable, I get the following error:
[b]get-eventlog : The network path was not found.
At line:1 char:1
- get-eventlog -ComputerName $machine -logname Application | select -Property Mac …[/b]
I’ve tried tweaking this all sorts of different ways to get it to read the $machine variable because it would be nice if I could import a large list of machines into the variable and then run the command that way.