Windows ã®æä½ãèªååãããã PowerShellã«è§¦ããã®ã«ãã£ã¨ãç°¡åãªé¡æã¯ããã§ã¯ãªãã§ããããã
ããããã°ã ããªã³ã¿ã¼ã«é¢ããæä½ã«ã¤ãã¦è§¦ãæ©ä¼ããªãã¦ç´¹ä»ãã¦ãã¾ããã§ããããå°ã触ã£ã¦ã¿ãã®ã§ç°¡åã«ã
ç®æ¬¡
- ç®æ¬¡
- Printer ã«é¢ããã³ãã³ãã¬ãã(Cmdlet)
- ç¾å¨ã®ããªã³ã¿ã¼ãã¼ããåå¾ãã
- ããªã³ã¿ã¼ãã¼ãã®è¿½å
- ããªã³ã¿ã¼ãã¼ãã®åé¤
- æ¢åããªã³ã¿ã¼ã¸ã®ãã¼ãã»ãã
- ã¾ã¨ã
Printer ã«é¢ããã³ãã³ãã¬ãã(Cmdlet)
PowerShell 3.0 ãã以ä¸ã®ã³ãã³ãã¬ãããå©ç¨å¯è½ã«ãªã£ã¦ãã¾ãã
ä¸é£ã®ã³ãã³ãã¬ããã¯ãPrintManagementã¢ã¸ã¥ã¼ã«ã«æ ¼ç´ããã¦ããã®ã§è¦ã¦ã¿ã¾ãããã
Get-Command -Module PrintManagement
CommandType Name ModuleName ----------- ---- ---------- Function Add-Printer PrintManagement Function Add-PrinterDriver PrintManagement Function Add-PrinterPort PrintManagement Function Get-PrintConfiguration PrintManagement Function Get-Printer PrintManagement Function Get-PrinterDriver PrintManagement Function Get-PrinterPort PrintManagement Function Get-PrinterProperty PrintManagement Function Get-PrintJob PrintManagement Function Read-PrinterNfcTag PrintManagement Function Remove-Printer PrintManagement Function Remove-PrinterDriver PrintManagement Function Remove-PrinterPort PrintManagement Function Remove-PrintJob PrintManagement Function Rename-Printer PrintManagement Function Restart-PrintJob PrintManagement Function Resume-PrintJob PrintManagement Function Set-PrintConfiguration PrintManagement Function Set-Printer PrintManagement Function Set-PrinterProperty PrintManagement Function Suspend-PrintJob PrintManagement Function Write-PrinterNfcTag PrintManagement
å¤ãã®ã³ãã³ãã¬ãããããã¾ããã
ä»åå©ç¨ããã®ã¯ã*-PrinterPort
ã³ãã³ãã¬ããã§ãã
Get-Command -Module PrintManagement -Noun PrinterPort
CommandType Name ModuleName ----------- ---- ---------- Function Add-PrinterPort PrintManagement Function Get-PrinterPort PrintManagement Function Remove-PrinterPort PrintManagement
ç¾å¨ã®ããªã³ã¿ã¼ãã¼ããåå¾ãã
ã¾ãã¯ãç¾å¨ã®ããªã³ã¿ã¼ãã¼ãåå¾ã§ãã
ããã¯ãGet-PrinterPort
ã³ãã³ãã¬ããã§å¯è½ã§ãã
Windows 8.1 ã¤ã³ã¹ãã¼ã«ç´å¾ã®ããã©ã«ãã¯ãããªæãã§ããã
Get-PrinterPort
Name ComputerName Description PortMonitor ---- ------------ ----------- ----------- LPT1: Local Port Local Monitor COM3: Local Port Local Monitor LPT2: Local Port Local Monitor COM4: Local Port Local Monitor LPT3: Local Port Local Monitor PORTPROMPT: Local Port Local Monitor FILE: Local Port Local Monitor COM1: Local Port Local Monitor COM2: Local Port Local Monitor nul: Local Port Local Monitor SHRFAX: Fax Monitor Port Microsoft Shared Fax Monitor
ããªã³ã¿ã¼ãã¼ãã®è¿½å
TCP/IPããªã³ã¿ã¼ãã¼ãã追å ãã¾ãããã
ããã¯ãAdd-PrinterPort
ã³ãã³ãã¬ããã§å¯è½ã§ããä¾ãã°ã192.168.11.200 ã®ããªã³ã¿ã¼ãã¼ãã追å ãã¦ã¿ã¾ãããã
TCP/IPããªã³ã¿ã¼ãã¼ãã¯ãé常ãã¼ãã¨å称ãåä¸ã§ä½ãã®ã§ãã®ã¾ã¾ã§ããã(Windowsã§GUIã使ã£ã¦è¿½å ããã¨ãã®ããã©ã«ãã®åä½)
[ipaddress]$TCPIPPort = "192.168.11.200" Add-PrinterPort -PrinterHostAddress $TCPIPport -Name $TCPIPport
ããã§ãGet-PrinterPort
ããã¨è¿½å çµæããããã¾ãã
Name ComputerName Description PortMonitor ---- ------------ ----------- ----------- COM1: Local Port Local Monitor COM2: Local Port Local Monitor COM3: Local Port Local Monitor COM4: Local Port Local Monitor FILE: Local Port Local Monitor LPT1: Local Port Local Monitor LPT2: Local Port Local Monitor LPT3: Local Port Local Monitor nul: Local Port Local Monitor PORTPROMPT: Local Port Local Monitor 192.168.11.200 Standard TCP/IP Port TCPMON.DLL SHRFAX: Fax Monitor Port Microsoft Shared Fax Monitor
ããªã³ã¿ã¼ãã¼ãã®åé¤
誤ã£ã¦è¿½å ããå ´åã¯ãRemove-PrinterPort
ã³ãã³ãã¬ããã§åé¤å¯è½ã§ãã
[ipaddress]$TCPIPPort = "192.168.11.200" Remove-PrinterPort -Name $TCPIPPort
æ¶ãã¦ã¾ããã
Name ComputerName Description PortMonitor ---- ------------ ----------- ----------- LPT1: Local Port Local Monitor COM3: Local Port Local Monitor LPT2: Local Port Local Monitor COM4: Local Port Local Monitor LPT3: Local Port Local Monitor PORTPROMPT: Local Port Local Monitor FILE: Local Port Local Monitor COM1: Local Port Local Monitor COM2: Local Port Local Monitor nul: Local Port Local Monitor SHRFAX: Fax Monitor Port Microsoft Shared Fax Monitor
æ¢åããªã³ã¿ã¼ã¸ã®ãã¼ãã»ãã
ãªãã®ã§ãããæ¢å®ã§ã¯ããã㯠CIM (WMI) ãå©ç¨ãã¾ãã
ããªã³ã¿ã¼ã®åå¾
ã¾ã㯠Win43_printer
ã§ããªã³ã¿ã¼ãåå¾ãã¾ãã
$printer = Get-CimInstance -Class Win32_printer | where name -eq $printerName
PortName ã®ã»ãã
ãã¨ã¯ãPortNameãã»ãããã¾ããåç´ã«ããã¨ããã§ããã
$printer.PortName = $TCPIPport
ãã¡ã³ã¯ã·ã§ã³
é¢åãªã®ã§ç¨æãã¾ããã
ããã¯Set-PrinterPort ã®ã¿ã®æ©è½ã§ãã
#Requires -Version 3.0 function Set-PrinterPort { <# .Synopsis Set TCP/IP to PrinterName you specified. .DESCRIPTION This Cmdlet will Assign current TCP/IP Port include what you specified. .EXAMPLE Set-PrinterPort -TCPIPport 192.168.1.2 -printerName "HP-hogehoge" .EXAMPLE Set-PrinterPort -TCPIPport 192.168.1.2 -printerName "HP-hogehoge" -Verbose #> [CmdletBinding()] Param ( # Input TCP/IP port number you want to create, assign to Printer [Parameter( Mandatory, Position = 0)] [ipaddress] $TCPIPport, # Input Printer Name to asshign Port Number you want [Parameter( Mandatory, Position = 1, ValueFromPipeline, ValueFromPipelineByPropertyName)] [string] $printerName ) process { if (-not(Get-PrinterPort | where Name -eq $TCPIPport)) { throw ("Printer Port '{0}' not found exception!" -f $TCPIPport) } else { Write-Verbose ("Printer port '{0}' found." -f $TCPIPport) } $printers = Get-CimInstance -Class Win32_printer | where name -eq $printerName if ($printers.count -ne 0) { foreach ($printer in $printers) { if ($printer.PortName -ne $TCPIPport) { Write-Verbose ("Setting Printer '{0}' port from '{1}' to '{2}'" -f $printer.Name, $printer.PortName, $TCPIPport) $printer.PortName = $TCPIPport } else { Write-Verbose ("Printer '{0}' port '{1}' was already '{2}'" -f $printer.Name, $printer.PortName, $TCPIPport) } } } else { throw ("Printer name '{0}' not exist exception!" -f $printerName) } } }
ãã£ã¡ã¯ãããªã³ã¿ã¼ãã¼ãã®æç¡ã確èªããªããã°è¿½å ãããã«æå®ããããªã³ã¿ã¼åã«ã»ããã¾ã§æ¡å¼µãããã®ã§ãã
#Requires -Version 3.0 function Set-PrinterPortExtend { <# .Synopsis Add/check TCP/IP and assign to PrinterName you specified. .DESCRIPTION This Cmdlet will check current TCP/IP Port include what you specified. If not exist, then add TCP/IP Port. Next, Get Printer Name as you desired and check Port Number which assigned to it. If PortNumber assigned was not same as Port Number you specified, then change it. .EXAMPLE Set-PrinterPort -TCPIPport 192.168.1.2 -printerName "HP*" .EXAMPLE Set-PrinterPort -TCPIPport 192.168.1.2 -printerName "HP*" -Verbose #> [CmdletBinding()] Param ( # Input TCP/IP port number you want to create, assign to Printer [Parameter( Mandatory, Position = 0)] [ipaddress] $TCPIPport, # Input Printer Name to asshign Port Number you want [Parameter( Mandatory, Position = 1, ValueFromPipeline, ValueFromPipelineByPropertyName)] [string] $printerName ) process { if (-not(Get-PrinterPort | where Name -eq $TCPIPport)) { if ($includeAddPort) { Write-Warning ("Printer port '{0}' not found. Adding port." -f $TCPIPport) Add-PrinterPort -PrinterHostAddress $TCPIPport -Name $TCPIPport } else { throw ("Printer Port '{0}' not found exception!" -f $TCPIPport) } } else { Write-Verbose ("Printer port '{0}' found." -f $TCPIPport) if ($PSBoundParameters.Verbose.IsPresent) { Get-PrinterPort | where Name -eq $TCPIPport } } $printers = Get-CimInstance -Class Win32_printer | where name -like $printerName if ($printers.count -ne 0) { foreach ($printer in $printers) { if ($printer.PortName -ne $TCPIPport) { Write-Verbose ("Setting Printer '{0}' port from '{1}' to '{2}'" -f $printer.Name, $printer.PortName, $TCPIPport) $printer.PortName = $TCPIPport } else { Write-Verbose ("Printer '{0}' port '{1}' was already '{2}'" -f $printer.Name, $printer.PortName, $TCPIPport) } } } else { throw ("Printer name '{0}' not exist exception!" -f $printerName) } } }
ã¾ã¨ã
ãªã Set-PrinterPort ãæ¢å®ã§ãªãã®ãè¬ã§ãããæµ·å¤ã®ãã©ã¼ã©ã ã§ãå°ã£ã¦ãã人ãå¤ããããªã®ã§ãæ¥æ¬èªè¨äºã«ãã¦ã¿ã¾ããã
ãå½¹ã«ç«ã¦ã°ä½ããã§ãã