?
Solved

I need this powershell script modified to export the machine name and what version of sep is on it into a csv or txt file

Posted on 2014-02-18
6
Medium Priority
?
742 Views
Last Modified: 2014-02-19
Currently this script will run against the hostlist.csv and echo the sep versionresults at the end.  I am looking for a way to get the computer names and sep version exported to a csv or txt file.

$File = Import-Csv 'c:\temp\hostlist.csv' #NOTE: the first line of this file must say machinename

foreach ($line in $file)
 
{
 
$machinename = $line.machinename
 
#Continue the script even if an error happens
 
trap [Exception] {continue}
 
 
 
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",$MachineName)
 
#Set the Reg Container
 
$key = "SOFTWARE\\Symantec\\Symantec Endpoint Protection\\SMC"
 
$regkey = "" #clears the value between loop runs
 
$regkey = $reg.opensubkey($key)
 
 
 
$SEPver = "" #clears the value between loop runs
 
#NOTE: the values between the " ' " symbols are the key you're looking for
 
$SEPver = $regKey.GetValue('ProductVersion')
 
$Results = $MachineName , $SEPver
 

Write-host $Results
 

}
0
Comment
Question by:scriptz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 2

Expert Comment

by:c_kedar
ID: 39868117
Not sure if I have understood your question correctly.
Assuming that your current script is already able to find the sep version on remote server and you need help only in formatting the the output, you only need to change last line to

Write-Host "$MachineName , $SEPver"

This will produce output in csv format which you can save in a file using output redirection (>).
0
 
LVL 40

Accepted Solution

by:
footech earned 2000 total points
ID: 39868152
Sorry, but the above suggestion wouldn't work.  You can't redirect Write-Host.
Using the foreach-Object cmdlet it's easy to pipe the results to Export-CSV, but when using the foreach statement it takes a bit more thought.  If you surround the foreach statement with array notation "@()", then you can pipe that to Export-CSV.  You could also manually construct a .CSV file line by line using Write-Output and cmdlets line Add-Content, but Export-CSV is a little simpler.
$File = Import-Csv 'c:\temp\hostlist.csv' #NOTE: the first line of this file must say machinename 

@(foreach ($line in $file)
{
    $machinename = $line.machinename
    #Continue the script even if an error happens
    trap [Exception] {continue}
 
    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",$MachineName)
    #Set the Reg Container
    $key = "SOFTWARE\\Symantec\\Symantec Endpoint Protection\\SMC"
    $regkey = "" #clears the value between loop runs
    $regkey = $reg.opensubkey($key)
 
    $SEPver = "" #clears the value between loop runs
    #NOTE: the values between the " ' " symbols are the key you're looking for
    $SEPver = $regKey.GetValue('ProductVersion')
 
    New-Object PsObject -Property @{
                                    Computer = $MachineName
                                    SEPVersion = $SEPver
                                    }
}) | Export-CSV results.csv -notype

Open in new window

0
 
LVL 70

Expert Comment

by:Qlemo
ID: 39868165
Certainly not. Write-Host writes to the console, no redirection here!
#NOTE: the first line of this file must say machinename 
Import-Csv 'c:\temp\hostlist.csv' | % {
  #Continue the script even if an error happens
  trap [Exception] {$SEPver = $regkey = ""; continue}

  $machinename = $_.machinename
  $reg    = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",$MachineName)
  $regkey = $reg.opensubkey('SOFTWARE\Symantec\Symantec Endpoint Protection\SMC')
  Write-Output $MachineName , $regKey.GetValue('ProductVersion')
} | Export-Csv -NoTypeInformation 'C:\temp\ee\SEPversion.csv'

Open in new window

However, do you really want to have the input file to be in CSV format for a single column only? Just using a text file containing all machine names would be sufficient ...
0
 
LVL 2

Expert Comment

by:c_kedar
ID: 39868167
My bad.
Use Write-Output instead of Write-Host.
0
 
LVL 40

Expert Comment

by:footech
ID: 39870009
:)  Everything should be triple-spaced...
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question