Printing

Using Powershell to generate Word document containing labels from CSV


In some situations you may have a CSV file containing names and addresses and you wish to print labels on standard Avery 5160 paper. You can manually do a mail merge in Word as outlined here or here. However, if you’re trying to automate the process for a recurring scenario, or in an application, or for a large number of CSV files, this script comes in handy.

This script requires MS Word 2003 or above installed on the computer where it is run. csv2Its input is a comma delimited CSV file containing the following headings:

‘First Name’,’Last Name’,’AddressNo’,’Address’,’City’,’State’,’Zip’

Its output is a Word document containing labels ready to print on standard Avery 5160 labels

Advertisements

Powershell script to change printer IP address


netprintA question was posted in Powershell.org Q&A forum:

I have a weird question. Can you modify object properties. the command
Get-PrinterPort 192.* | fl *
prints out all the attributes of the printer port. but I can’t modify them. I don’t want to create a new port and start from scratch, just modify the existing object. Or maybe export the export and then import it, modified, into the new one.

This script does just that. It can be downloaded from the Microsoft Script Center Repository.

The reason we cannot modify the existing printer port object is that the Get-Printer commandlet uses the MSFT_TCPIpPrinterPort class. This class has the 2 properties we want to change (HostAddress and Name) but they’re read-only.

Even if we try to use the Win32_TCPIpPrinterPort class, as in:

$OldIP = “192.168.0.95”
$NewIP = “192.168.0.99”
$objPrinterPort = Get-WmiObject -Class Win32_TCPIpPrinterPort | Where-Object {$_.Name -eq “IP_$OldIP”}
$objPrinterPort.psbase.scope.options.EnablePrivileges = $true
$objPrinterPort.HostAddress = $NewIP
$objPrinterPort.Name = “IP_$NewIP”
$objPrinterPort.Put()

This does not modify the existing Printer Port, it creates a new one..

Example script usage:

.\Change-PrinterIP.ps1 192.168.0.95 192.168.0.99

Script output looks like:

Change-PrinterIP