Create script that would search for list of printer serial number ?

Hi

I am looking for Power script  that can search for printers by serial number and will  generate CSV output file with

ip address:
hostname:
mac address:
fax#

Thx. Mike
Devinv.csv
michalek19Asked:
Who is Participating?
 
RobSampsonCommented:
Hi, try this.

# Input File
$InputFile = 'C:\Temp\Scripts\Devinv.csv'
# Output File
$OutputFile = 'C:\Temp\Scripts\DevSel.csv'
# Possible Search Fields
$searchFields = "Serial Number", "IP Address", "Hardware Address (MAC)"
# Select the index of the search field here
$searchField = $searchFields[0] # Serial Number
#$searchField = $searchFields[1] # IP Address
#$searchField = $searchFields[2] # MAC Address
# Enter the items you want to find here
$searchItems = 'CN37PEK09Z', 'CNB9B8FBB2' # Serial Number
#$searchItems = '10.76.58.9', '10.76.58.6' # IP Address
#$searchItems = '001438A4D24A', '0014383D536E' # MAC Address
# This will perform the search
Select-String -Pattern '^,[\s\d]' -Path $InputFile | ConvertFrom-CSV | 
  Where-Object { $searchItems -contains $_."$searchField" } |
  Select 'Serial Number', 'IP Address', 'IP Hostname', 'Fax' #|
  Export-CSV -NoType $OutputFile
#Invoke-Item $OutputFile

Open in new window


Note that you need to select the appropriate $searchField to search for from this list:
$searchField = $searchFields[0] # Serial Number
$searchField = $searchFields[1] # IP Address
$searchField = $searchFields[2] # MAC Address


And also the items you want to search for from this list:
$searchItems = 'CN37PEK09Z', 'CNB9B8FBB2' # Serial Number
$searchItems = '10.76.58.9', '10.76.58.6' # IP Address
$searchItems = '001438A4D24A', '0014383D536E' # MAC Address

Regards,

Rob.
0
 
RobSampsonCommented:
Hi Mike, are you asking just to filter that input file based on a serial number entered by the user?

Rob.
0
 
michalek19Author Commented:
What i am looking for is to run script against printer archived  inventory csv file and filter "search"  only serial numbers that i need to find it. The output should create serial number, IP address, hostname, MAC address, FAX#.
0
How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Guess the best way is to extract the "real CSV data" part, import it, and then do some selection and processing:
$sn = 'CN37PEK09Z', 'CNB9B8FBB2'
select-string -Pattern '^,[\s\d]' -Path C:\Temp\EE\Devinv.csv | convertFrom-CSV |
  ? { $sn -contains $_.{Serial Number} } |
  select 'Serial Number', 'IP Address', 'IP Hostname', 'Fax' |
  export-CsV -NoType C:\Temp\EE\DevSel.csv

Open in new window

Note there is no MAC address in the inventory CSV.
0
 
michalek19Author Commented:
I will check this method
0
 
michalek19Author Commented:
This looks good but how i can also search for MAC address and Serial number and IP address.
I want to have option to choose during the search.
Also, i want to provide input file ".csv" file  that would contain Serial numbers or MAC address or IP address
Devinv.csv
0
 
michalek19Author Commented:
i will check this
0
 
Martin LissOlder than dirtCommented:
I've requested that this question be closed as follows:

Accepted answer: 250 points for Qlemo's comment #a40693617
Assisted answer: 250 points for RobSampson's comment #a40728838

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.