Select-string on remote computers and getting the results via out-file


hi guys,

i ask approach regarding below script main goal query given log file , match/find given string in log file i.e. error message.

$erroractionpreference = "silentlycontinue"
$sys = get-content .\systems.txt
$searchstr = "8007000e"
foreach ($system in $sys)
{
$location = "\\$system\c$\windows\windowsupdate.log" select-string -path $location -pattern $searchstr | 

select-object -first 1

| format-table -property  path, pattern | out-file -filepath  "c:\results\string_match_results.txt"

}

in general works single station below:
path                                                                        pattern                                     
----                                                                            -------                                     
\\polpc1\c$\windows\windowsupdate.log           8007000e 

however getting empty output file when there’s more 1 machine on get-content list.

do need use invoke-commend or similar? many in advance suggestions.



hi,

drop format-table command , use select-object statement only. you'll need add -append switch out-file or change foreach-object loop , put out-file outside of loop.




Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

CRL Revocation always failed

0x300000d errors in Microsoft Remote Desktop client

Failed to query the results of bpa xpath