Powershell: Get your printers ready

Ready to use functions for your next printer script:

Create Printer


function CreatePrinter {
$server = $args[0]
$print = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_Printer").createInstance()
$print.drivername = $args[1]
$print.PortName = $args[2]
$print.Shared = $true
$print.published = $true
$print.Sharename = $args[3]
$print.Location = $args[4]
$print.Comment = $args[5]
$print.DeviceID = $args[6]


createprinter servername drivername portname sharename location comment deviceID

DeviceID and Sharename may be the same. Disable $print.shared and .published if you do not want the printer to be created in AD.
This is great for creating a printer via CSV File.

Create Printer Port

function CreatePrinterPort {
$server =  $args[0]
$port = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()
$port.Name= $args[1]
$port.HostAddress= $args[2]


CreatePrinterPort servername portname hostaddress

Create the ports first if they do not already exist!

Delete Printer

function DeletePrinter {
    Get-WmiObject -class "Win32_Printer" -ComputerName $Server -namespace "root\CIMV2" |
    Where-Object {$_.name -eq $printer} | ForEach-Object {

Rename Printer

function RenamePrinter {
    Invoke-WmiMethod -path "Win32_Printer.DeviceID='$oldname'" -name RenamePrinter -ArgumentList "$newname" -ComputerName "$server"

MOTD for Powershell (Using the fortune-mod (linux) Package files)

I downloaded and altered the fortune-mod fortune files so that there’s one fortune per line. This can be downloaded here:

Next step is to add the following thing to your $Profile

function get-motd{
$fortunes = get-content \path\to\fortunes.txt
get-random -InputObject $fortunes

It’s virtually important that you run the function after the clear-host. Otherwise the quote will not appear / will be erradicated before it even had time to present itself to you)