Solved

Powershell Script

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now