Hi All,
I was wondering how I would convert the below to output to CSV and NOT call excel, as I dont have it on the server and keep the same format, so it outputs into two columns, with just the IP and Name. Thanks in advance. Script works just need it to interface with notepad rather than excel.
Kind Regards,
Sean,
$Printserver = "Printserver"
$Excel = new-Object -comobject Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Item(1)
$Sheet.Cells.Item(1,2) = "Printer Name"
$Sheet.Cells.Item(1,1) = "IP Address"
$intRow = 2
$WorkBook = $Sheet.UsedRange
$WorkBook.Font.Bold = $True
$Printers = Get-WMIObject Win32_Printer -computername $Printserver
foreach ($Printer in $Printers)
{
$Sheet.Cells.Item($intRow, 2) = $Printer.Name
$Ports = Get-WmiObject Win32_TcpIpPrinterPort -computername $Printserver
foreach ($Port in $Ports)
{
if ($Port.Name -eq $Printer.PortName)
{
$Sheet.Cells.Item($intRow, 1) = $Port.HostAddress | %{"{0:000}.{1:000}.{2:000}.{3:000}" -f @([int[]]$_.split('.'))}
}
}
}
$WorkBook.EntireColumn.AutoFit()
$intRow = $intRow + 1
$Sheet.Cells.Item($intRow,1).Font.Bold = $True
$Sheet.Cells.Item($intRow,1) = ""