• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

Powershell Script

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
erwin_miranda
Asked:
erwin_miranda
1 Solution
 
erwin_mirandaAuthor Commented:
Disregard this request...I found a better script...
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now