First time PowerShell programmer Ok so I have an environment that uses IP printing We have several different printers I would like to use power shell to script the addition of printer. I found a power shell script that will do that (see below) I have taken out items that are specific to my business. What I’m trying to figure out is where (or how) do I set the execution policy to run. The policy is set to restricted, so I know that I can temporally set it to prompt so the printers can be installed. I’m pretty sure that it can’t be done within powershell. Here’s the script, I just need to figure out how I get it to run. #################################################### # Change these values to the appropriate values in your environment
If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.
PowerShell to add printers
Ok so I have an environment that uses IP printing
We have several different printers
I would like to use power shell to script the addition of printer.
I found a power shell script that will do that (see below) I have taken out items that are specific to my business.
What I’m trying to figure out is where (or how) do I set the execution policy to run.
The policy is set to restricted, so I know that I can temporally set it to prompt so the printers can be installed.
I’m pretty sure that it can’t be done within powershell.
Here’s the script, I just need to figure out how I get it to run.
####################################################
# Change these values to the appropriate values in your environment
$PrinterIP = "x.x.x.x"
$PrinterPort = "TCP/IP"
$PrinterPortName = "IP_" + $PrinterIP
$DriverName = "Printername"
$DriverPath = "\\unc path to drivers \"
$DriverInf = "\\unc path to inf OEMSETUP.inf"
$PrinterCaption = "name of printer caption "
####################################################
Function CreatePrinterPort {
param ($PrinterIP, $PrinterPort, $PrinterPortName)
$wmi = [wmiclass]"\\root\cimv2:win32_tcpipPrinterPort"
$wmi.psbase.scope.options.enablePrivileges = $true
$Port = $wmi.createInstance()
$Port.name = $PrinterPortName
$Port.hostAddress = $PrinterIP
$Port.portNumber = $PrinterPort
$Port.SNMPEnabled = $false
$Port.Protocol = 1
$Port.put()
}
Function InstallPrinterDriver {
Param ($DriverName, $DriverPath, $DriverInf)
$wmi = [wmiclass]"\\$ComputerName\Root\cimv2:Win32_PrinterDriver"
$wmi.psbase.scope.options.enablePrivileges = $true
$wmi.psbase.Scope.Options.Impersonation = `
[System.Management.ImpersonationLevel]::Impersonate
$Driver = $wmi.CreateInstance()
$Driver.Name = $DriverName
$Driver.DriverPath = $DriverPath
$Driver.InfName = $DriverInf
$wmi.AddPrinterDriver($Driver)
$wmi.Put()
}
Function CreatePrinter {
param ($PrinterCaption, $PrinterPortName, $DriverName)
$wmi = ([WMIClass]"\\Root\cimv2:Win32_Printer")
$Printer = $wmi.CreateInstance()
$Printer.Caption = $PrinterCaption
$Printer.DriverName = $DriverName
$Printer.PortName = $PrinterPortName
$Printer.DeviceID = $PrinterCaption
$Printer.Put()
}
####################################################
Thank you in advance