|
ここからは、Windows PowerShell Brackets のサンプルを紹介します。
- $colItems = Get-WmiObject -class $WmiClass
次の事例を実行してみよう。
# http://www.computerperformance.co.uk/powershell/powershell_brackets.htm
# PowerShell cmdlet to demonstrate brackets
$WmiClass = "Win32_NetworkAdapterConfiguration"
$colItems = Get-WmiObject -class $WmiClass
ForEach ($objItem in $colItems)
{
Write-Host $objItem.caption
Write-Host $objItem.ipaddress
Write-Host $objItem.macAddress
}
# $colItems
3〜4行で、ネットワークアダプタの設定を取得しています。
5〜10行で、各アダプタの名前、IPアドレス及びマックアドレスを表示しています。
それでは、実行してみましょう。下記のような結果が得られます。
[00000000] Microsoft Kernel Debug Network Adapter
[00000001] Marvell Yukon 88E8056 PCI-E Gigabit Ethernet Controller
192.168.x.xx
00:1F:xx:xx:xx:xx
[00000002] Microsoft Teredo Tunneling Adapter
[00000003] Microsoft ISATAP Adapter
[00000005] Microsoft ISATAP Adapter
上記を実行すると
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 -List | Where-Object {$_.name -Match "win32*"}
次の事例を実行してみよう。
# PowerShell curly bracket example
Get-WmiObject -List | Where-Object {$_.name -Match "win32*"}
WMI オブジェクトを取得して、Name の中に "win32*" の文字列があるものを表示しています。
それでは、実行してみましょう。下記のような結果が得られます。
NameSpace: ROOT\cimv2
Name Methods Properties
---- ------- ----------
Win32_PrivilegesStatus {} {Description, Operation, ParameterInfo, Privile...
Win32_JobObjectStatus {} {AdditionalDescription, Description, Operation,...
Win32_Trustee {} {Domain, Name, SID, SidLength...}
Win32_ACE {} {AccessMask, AceFlags, AceType, GuidInheritedOb...
Win32_SecurityDescriptor {} {ControlFlags, DACL, Group, Owner...}
Win32_ComputerSystemEvent {} {MachineName, SECURITY_DESCRIPTOR, TIME_CREATED}
Win32_ComputerShutdownEvent {} {MachineName, SECURITY_DESCRIPTOR, TIME_CREATED...
Win32_IP4RouteTableEvent {} {SECURITY_DESCRIPTOR, TIME_CREATED}
< 省略 >
上記を実行すると
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 Win32_Computersystem | Get-Member -Membertype property [a-z]*
次の事例を実行してみよう。
# Example of PowerShell Square Bracket
Clear-Host
Get-WmiObject Win32_Computersystem | Get-Member -Membertype property [a-z]*
Win32_Computersystem の WMI オブジェクトのメンバーを取得して、-Membertype が Property で、英文字名のものを表示します。
それでは、実行してみましょう。下記のような結果が得られます。
TypeName: System.Management.ManagementObject#root\cimv2\Win32_ComputerSystem
Name MemberType Definition
---- ---------- ----------
AdminPasswordStatus Property uint16 AdminPasswordStatus {get;set;}
AutomaticManagedPagefile Property bool AutomaticManagedPagefile {get;set;}
AutomaticResetBootOption Property bool AutomaticResetBootOption {get;set;}
AutomaticResetCapability Property bool AutomaticResetCapability {get;set;}
BootOptionOnLimit Property uint16 BootOptionOnLimit {get;set;}
BootOptionOnWatchDog Property uint16 BootOptionOnWatchDog {get;set;}
BootROMSupported Property bool BootROMSupported {get;set;}
BootStatus Property uint16[] BootStatus {get;set;}
BootupState Property string BootupState {get;set;}
Caption Property string Caption {get;set;}
< 省略 >
上記を実行すると
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-Process [p]*
次の事例を実行してみよう。
# ----< 正規表現の事例 [p-s]* など >----
# Get-Process [r-s]*
Get-Process [p]*
稼働中のプロセスを取得して、正規表現 [p]* に一致したものを表示しています。
それでは、実行してみましょう。下記のような結果が得られます。
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id SI ProcessName
------- ------ ----- ----- ----- ------ -- -- -----------
535 18 54448 61664 300 12.09 7184 2 powershell
469 14 47884 33156 287 1.17 7880 2 powershell
86 3 640 3636 24 0.03 2392 0 PsiService_2
上記を実行すると
PowerShell 7.15 でも、正常(同様)に、実行されます。
テーブルの構成が若干異なるよう。
PowerShell 7.4.6 でも、同様です。
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName
------ ----- ----- ------ -- -- -----------
9 1.22 5.09 0.00 3448 0 PsiService_2
7 1.12 4.64 0.00 3488 0 PsiService_2
111 65.35 147.69 32.81 13180 2 pwsh
|