|
ここでは、PowerShell Printer Scripts のサンプルを紹介します。
- Get-WmiObject -List | where {$_.name -Match "Printer"}
次の事例を実行してみよう。
# http://www.computerperformance.co.uk/powershell/powershell_printers.htm
# PowerShell to list WMI Printer Objects
# Author: Guy Thomas
Get-WmiObject -List | where {$_.name -Match "Printer"}
WMI オブジェクト一覧を取得して、.name に "Printer" があるものを表示します。
それでは、実行してみましょう。下記のような結果が得られます。
NameSpace: ROOT\cimv2
Name Methods Properties
---- ------- ----------
CIM_Printer {SetPowerState, R... {Availability, AvailableJobSheets, ...
Win32_Printer {SetPowerState, R... {Attributes, Availability, Availabl...
Win32_PrinterDriver {StartService, St... {Caption, ConfigFile, CreationClass...
Win32_TCPIPPrinterPort {} {ByteCount, Caption, CreationClassN...
Win32_PrinterConfiguration {} {BitsPerPel, Caption, Collate, Colo...
Win32_PrinterSetting {} {Element, Setting}
Win32_PrinterShare {} {Antecedent, Dependent}
Win32_PrinterDriverDll {} {Antecedent, Dependent}
Win32_PrinterController {} {AccessState, Antecedent, Dependent...
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- Get-WmiObject -class $Class | ft name, systemName, shareName -auto
次の事例を実行してみよう。
# PowerShell Script for Printers
# Author: Guy Thomas
# Clear-Host
$Class = "win32_printer"
Get-WmiObject -class $Class | ft name, systemName, shareName -auto
4〜5行で、"win32_printer" クラスの WMI オブジェクト一覧を取得して、name, systemName, shareName のテーブルに整形して、表示します。
それでは、実行してみましょう。下記のような結果が得られます。
name systemName shareName
---- ---------- ---------
RICOH imagio MP C7500 PS (1 コピー) KAMIFUJI-PC7-14
RICOH imagio MP C7500 PS KAMIFUJI-PC7-14
OneNote 2010 に送る KAMIFUJI-PC7-14
Microsoft XPS Document Writer KAMIFUJI-PC7-14
Microsoft Print to PDF KAMIFUJI-PC7-14
HP Designjet Z6200ps 60in PS3 KAMIFUJI-PC7-14
HP Designjet 4500ps PS3 KAMIFUJI-PC7-14
HP Designjet 4500ps HPGL2 KAMIFUJI-PC7-14
Fax KAMIFUJI-PC7-14
EPSON2119B0 (EP-807A Series) (1 コピー) KAMIFUJI-PC7-14
EPSON2119B0 (EP-807A Series) KAMIFUJI-PC7-14
EP-807A Series(ネットワーク) KAMIFUJI-PC7-14
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- foreach ($machine in $arrayComp) { .. }
次の事例を実行してみよう。
# PowerShell array to List Printers
# Author: Guy Thomas
$Class = "win32_printer"
$arrayComp ="kamifuji-pc7-14", "kamifuji-xp11"
foreach ($machine in $arrayComp) {
Get-WmiObject -class $Class -computername $machine |`
ft name, systemName, shareName -auto }
4行目で、"kamifuji-pc7-14" と "kamifuji-xp11" を $arrayComp 配列に格納します。
5〜7行で、$arrayComp から 1個のコンピュータ名を $machine 取り出して、"win32_printer" クラスの WMI オブジェクト一覧を取得して、name, systemName, shareName のテーブルに整形して、表示します。
それでは、実行してみましょう。下記のような結果が得られます。
name systemName shareName
---- ---------- ---------
RICOH imagio MP C7500 PS (1 コピー) KAMIFUJI-PC7-14
RICOH imagio MP C7500 PS KAMIFUJI-PC7-14
OneNote 2010 に送る KAMIFUJI-PC7-14
Microsoft XPS Document Writer KAMIFUJI-PC7-14
Microsoft Print to PDF KAMIFUJI-PC7-14
HP Designjet Z6200ps 60in PS3 KAMIFUJI-PC7-14
HP Designjet 4500ps PS3 KAMIFUJI-PC7-14
HP Designjet 4500ps HPGL2 KAMIFUJI-PC7-14
< 省略 >
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- $GMProp = Get-WmiObject -class $Class | gm -memberType property | where {$_.name -Notmatch "__*"}
次の事例を実行してみよう。
# PowerShell cmdlet to investigate win32_printer properties
# Author: Guy Thomas
$Class = "Win32_printer"
$GMProp = Get-WmiObject -class $Class | gm -memberType property `
| where {$_.name -Notmatch "__*"}
$GMProp
$GMProp.count
3〜5行で、"Win32_printer" クラスの WMI オブジェクトから、-memberType が property のメンバーを取得して、.name に "__*" が無いものを $GMProp に格納します。
6行目で、$GMProp を表示します。
7行目で、$GMProp の個数を表示します。
それでは、実行してみましょう。下記のような結果が得られます。
TypeName: System.Management.ManagementObject#root\cimv2\Win32_Printer
Name MemberType Definition
---- ---------- ----------
Attributes Property uint32 Attributes {get;set;}
Availability Property uint16 Availability {get;set;}
AvailableJobSheets Property string[] AvailableJobSheets {get;set;}
AveragePagesPerMinute Property uint32 AveragePagesPerMinute {get;set;}
Capabilities Property uint16[] Capabilities {get;set;}
CapabilityDescriptions Property string[] CapabilityDescriptions {get;set;}
Caption Property string Caption {get;set;}
CharSetsSupported Property string[] CharSetsSupported {get;set;}
< 省略 >
UntilTime Property string UntilTime {get;set;}
VerticalResolution Property uint32 VerticalResolution {get;set;}
WorkOffline Property bool WorkOffline {get;set;}
86
上記を実行すると
PowerShell 7.15 では、エラーです。何故か Object が無い??
Get-WmiObject: The term 'Get-WmiObject' is not recognized as a name
of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
PowerShell 7.4.6 でも、同様です。
|