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
Solved

Powershell Script

Posted on 2014-01-22
1
376 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
1 Comment
 

Accepted Solution

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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Synchronize a new Active Directory domain with an existing Office 365 tenant

856 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