Solved

Powershell Script

Posted on 2014-01-22
1
380 Views
Last Modified: 2014-01-22
I found this script on the internet....
I woudld like to keep the contents of the exel spread shee to one exel, this script creates a book, is there a way to write the server name to the book instead of book 1 or 2 etc..here is the code
# Set print server name
$Printservers = Get-Content -path "C:\Users\%username%\Desktop\ServerList.txt"
 foreach ($Printserver in $Printservers)
{
# Create new Excel workbook
$Excel = new-Object -comobject Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Item(1)
$Sheet.Cells.Item(1,1) = "Server Name"
$Sheet.Cells.Item(1,2) = "Printer Name"
$Sheet.Cells.Item(1,3) = "Location"
$Sheet.Cells.Item(1,4) = "Comment"
$Sheet.Cells.Item(1,5) = "IP Address"
$Sheet.Cells.Item(1,6) = "Driver Name"
$Sheet.Cells.Item(1,7) = "Shared"
$Sheet.Cells.Item(1,8) = "Share Name"
$intRow = 2
$WorkBook = $Sheet.UsedRange
$WorkBook.Font.Bold = $True

# Get printer information
$Printers = Get-WMIObject Win32_Printer -computername $Printserver
foreach ($Printer in $Printers)
{
    
    $Sheet.Cells.Item($intRow, 1) = $Printserver
    $Sheet.Cells.Item($intRow, 2) = $Printer.Name
    $Sheet.Cells.Item($intRow, 3) = $Printer.Location
    $Sheet.Cells.Item($intRow, 4) = $Printer.Comment
    $Ports = Get-WmiObject Win32_TcpIpPrinterPort -computername $Printserver
        foreach ($Port in $Ports)
        {
            if ($Port.Name -eq $Printer.PortName)
            {
            $Sheet.Cells.Item($intRow, 5) = $Port.HostAddress
            }
        }
    $Sheet.Cells.Item($intRow, 6) = $Printer.DriverName
    $Sheet.Cells.Item($intRow, 7) = $Printer.Shared
    $Sheet.Cells.Item($intRow, 8) = $Printer.ShareName
    $intRow = $intRow + 1
}

$WorkBook.EntireColumn.AutoFit()
$intRow = $intRow + 1
$Sheet.Cells.Item($intRow,1).Font.Bold = $True
#extra code...not needed really testing purpose


}

Open in new window

0
Comment
Question by:erwin_miranda
[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
1 Comment
 

Accepted Solution

by:
erwin_miranda earned 0 total points
ID: 39800696
Disregard this request...I found a better script...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

717 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