|
ここでは、PowerShell's Comparison Operators のサンプルを紹介します。
Powershell のオペレータについてのサンプルです。
- $List = $Dir | Where-Object {$_.extension -eq ".dll"}
次の事例を実行してみよう。
# http://www.computerperformance.co.uk/powershell/powershell_comparison_operators.htm
# PowerShell script to list DLLs under system32 folder
$Dir = Get-Childitem C:\windows\system32 -recurse -EA SilentlyContinue
$List = $Dir | Where-Object {$_.extension -eq ".dll"}
$List | Format-Table Name, CreationTime -auto
3行目では、C:\windows\system32 から再帰的にアイテムを検索取得し、$Dir に格納します。
4行目では、$Dir から拡張子が ".dll" であるものを $List に格納します。
5行目では、$List から Name, CreationTime にテーブル成形します。
それでは、実行してみましょう。下記のような結果が得られます。
Name CreationTime
---- ------------
aadauthhelper.dll 2015/10/30 14:44:48
aadcloudap.dll 2016/07/13 11:54:51
aadtb.dll 2016/07/13 11:55:08
AboveLockAppHost.dll 2016/04/13 10:32:19
accessibilitycpl.dll 2015/10/30 14:44:50
accountaccessor.dll 2016/04/13 10:32:28
AccountsControlInternal.dll 2015/10/30 14:45:04
AccountsRt.dll 2016/04/13 10:32:35
ACCTRES.dll 2015/10/30 14:44:51
acledit.dll 2015/10/30 14:44:40
< 省略 6gt;
上記を実行すると
PowerShell 7.15 でも、正常(同様)に、実行されます。
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- $DNS = (Test-Connection www.google.com -quiet)
次の事例を実行してみよう。
# PowerShell Script to Test An Internet Connection
$DNS = (Test-Connection www.google.com -quiet)
If($DNS -eq "True") {Write-Host "The internet is available"}
ElseIf($DNS -ne "True") {Restart-Service dnscache}
2行目では、Test-Connection で、www.google.com への接続を確認します。
3〜4行で、接続状況に応じて、処理を振り分けています。
それでは、実行してみましょう。下記のような結果が得られます。
The internet is available
上記を実行すると
PowerShell 7.15 では、エラーです。何故か ElseIf が無い??
PowerShell 5.0 の時は、問題なかったようだが、PowerShell 5.1 では、同様に、エラーです。
ElseIf: The term 'ElseIf' 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 では、エラーなしの正常実行です。
[ 目次 ]
- $file.name + "`t " +$file.length + "`t " + $file.LastAccessTime
次の事例を実行してみよう。
# PowerShell Comparison Operator -eq in Foreach Loop
"File Name " + "`t Size" +"`t Last Accessed"
foreach ($file in Get-Childitem)
{If ($file.extension -eq ".txt")
{
$file.name + "`t " +$file.length + "`t " + $file.LastAccessTime
}
}
カレントディレクトリの拡張子が ".txt" であるものを抽出して、タブ区切りで表示します。
"`t" は、タブにエスケープします。
それでは、実行してみましょう。下記のような結果が得られます。
File Name Size Last Accessed
014_PS_CompareRegistry_02.txt 15514 07/01/2016 16:29:00
016_PS_Drives_03.txt 23942 07/01/2016 17:43:07
017_PS_NewPSDrive_01.txt 23942 07/02/2016 09:33:10
017_PS_NewPSDrive_04.txt 116046 07/02/2016 10:19:18
017_PS_NewPSDrive_04_1.txt 219764 07/02/2016 10:20:51
018_PS_GetPSDrive_07.txt 38636 07/02/2016 14:01:36
019_PS_GetEventlog_07.txt 28688 07/02/2016 14:29:33
019_PS_GetEventlog_08.txt 380608 07/02/2016 14:31:22
020_PS_WinEvent_08.txt 52722 07/02/2016 15:03:51
Checkout.txt 65 07/01/2016 14:29:46
ShopList.txt 84 07/01/2016 14:28:58
上記を実行すると
PowerShell 7.15 でも、正常(同様)に、実行されます。
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- $Block | Where-Object {$_.length -gt 2MB}
次の事例を実行してみよう。
# ---< >----
# Clear-Host
$FileSource ="F:\pdf_buff\"
$Block = Get-ChildItem -path $Filesource -Recurse
$Block | Where-Object {$_.length -gt 2MB}
"F:\pdf_buff\" から再帰的にアイテムを検索取得して、ファイルサイズが 2MB 越えのアイテムを表示します。
それでは、実行してみましょう。下記のような結果が得られます。
ディレクトリ: F:\pdf_buff
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2015/06/12 8:02 5124934 仕事ができない人.pdf
-a---- 2015/07/23 16:09 5126463 仕事ができない人_pw.pdf
-a---- 2015/07/19 17:23 5126271 仕事ができない人_pw_up.pdf
ディレクトリ: F:\pdf_buff\pdf03
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2016/06/13 10:51 3510729 aa.ps
-a---- 2016/06/16 15:31 13003416 aa01.ps
-a---- 2016/02/25 12:42 6553383 _0001.ps
< 省略 6gt;
上記を実行すると
PowerShell 7.15 でも、正常(同様)に、実行されます。
Get-ChildItem( ls ) の表示について、PowerShell 5.1 では、デスク上の保存順に表示されているが、PowerShell 7.15 では、Name でソートされて表示してくれます。
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- For ( $i = 12; $i -le 144; $i+=12 ) { $i }
次の事例を実行してみよう。
# ----< for loop >----
For ( $i = 12; $i -le 144; $i+=12 ) { $i }
For ループのサンプルです。
それでは、実行してみましょう。下記のような結果が得られます。
12
24
36
48
60
72
84
96
108
120
132
144
上記を実行すると
PowerShell 7.15 でも、正常(同様)に、実行されます。
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- Get-WmiObject -List | Where-Object {$_.name -Like "*Adapter"}
次の事例を実行してみよう。
# PowerShell -Like Operator
# Author: Guy Thomas
# Version September 2011 tested on PowerShell v 2.0
# Version July 2016 tested on PowerShell v 5.0
# Clear-Host
Get-WmiObject -List | Where-Object {$_.name -Like "*Adapter"}
WMI オブジェクトを取得して、最後尾が "*Adapter" であるものを表示します。
それでは、実行してみましょう。下記のような結果が得られます。
NameSpace: ROOT\CIMV2
Name Methods Properties
---- ------- ----------
CIM_NetworkAdapter {SetPowerState, R... {AutoSense, Availability, Caption, ConfigManagerErrorCod...
Win32_NetworkAdapter {SetPowerState, R... {AdapterType, AdapterTypeId, AutoSense, Availability...}
Win32_PerfFormattedData_Tcpip_Ne... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
Win32_PerfRawData_Tcpip_NetworkA... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
上記を実行すると
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 -Like "*Adapter*"}
次の事例を実行してみよう。
# PowerShell example to demonstrate -Like
# Author: Guy Thomas
# Version September 2011 tested on PowerShell v 2.0
# Version July 2016 tested on PowerShell v 5.0
# Clear-Host
Get-WmiObject -List | Where-Object {$_.name -Like "*Adapter*"}
WMI オブジェクトを取得して、途中でも "*Adapter*" であるものを表示します。
それでは、実行してみましょう。下記のような結果が得られます。
NameSpace: ROOT\CIMV2
Name Methods Properties
---- ------- ----------
CIM_NetworkAdapter {SetPowerState, R... {AutoSense, Availability, Caption, ConfigManagerErrorCod...
Win32_NetworkAdapter {SetPowerState, R... {AdapterType, AdapterTypeId, AutoSense, Availability...}
Win32_NetworkAdapterConfiguration {EnableDHCP, Rene... {ArpAlwaysSourceRoute, ArpUseEtherSNAP, Caption, Databas...
Win32_NetworkAdapterSetting {} {Element, Setting}
Win32_PerfFormattedData_Tcpip_Ne... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
Win32_PerfRawData_Tcpip_NetworkA... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
上記を実行すると
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 "Adapter"}
次の事例を実行してみよう。
# PowerShell example to check with -Match
# Author: Guy Thomas
# Version September 2011 tested on PowerShell v 2.0
# Version July 2016 tested on PowerShell v 5.0
# Clear-Host
Get-WmiObject -List | Where-Object {$_.name -Match "Adapter"}
WMI オブジェクトを取得して、途中でも "*Adapter*" であるものを表示します。
結果は、前項と同じです。
それでは、実行してみましょう。下記のような結果が得られます。
NameSpace: ROOT\CIMV2
Name Methods Properties
---- ------- ----------
CIM_NetworkAdapter {SetPowerState, R... {AutoSense, Availability, Caption, ConfigManagerErrorCod...
Win32_NetworkAdapter {SetPowerState, R... {AdapterType, AdapterTypeId, AutoSense, Availability...}
Win32_NetworkAdapterConfiguration {EnableDHCP, Rene... {ArpAlwaysSourceRoute, ArpUseEtherSNAP, Caption, Databas...
Win32_NetworkAdapterSetting {} {Element, Setting}
Win32_PerfFormattedData_Tcpip_Ne... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
Win32_PerfRawData_Tcpip_NetworkA... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
上記を実行すると
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 でも、同様です。
[ 目次 ]
- where-Object {$_.name -NotLike "CIM*" -And $_.name -NotLike "__*"}
次の事例を実行してみよう。
# PowerShell example to list demonstrate -NotLike with -And
# Author: Guy Thomas
# Version September tested on PowerShell v 2
# Version July 2016 tested on PowerShell v 5.0
# Clear-Host
$WMI = Get-WmiObject -List `
| where-Object {$_.name -NotLike "CIM*" -And $_.name -NotLike "__*"}
$WMI
Write-Host `n $WMI.count "WMI objects not contain CIM or __"
WMI オジェクトを取得して、先頭が CIM でも __ でもないものを表示します。
それでは、実行してみましょう。下記のような結果が得られます。
NameSpace: ROOT\cimv2
Name Methods Properties
---- ------- ----------
Win32_DeviceChangeEvent {} {EventType, SECURITY_DESCRIPTOR, TIME_CREATED}
Win32_SystemConfigurationChangeE... {} {EventType, SECURITY_DESCRIPTOR, TIME_CREATED}
Win32_VolumeChangeEvent {} {DriveName, EventType, SECURITY_DESCRIPTOR, TIME_CREATED}
MSFT_WMI_GenericNonCOMEvent {} {ProcessId, PropertyNames, PropertyValues, ProviderName...}
MSFT_NCProvEvent {} {Namespace, ProviderName, Result, SECURITY_DESCRIPTOR...}
MSFT_NCProvCancelQuery {} {ID, Namespace, ProviderName, Result...}
MSFT_NCProvClientConnected {} {Inproc, Namespace, ProviderName, Result...}
MSFT_NCProvNewQuery {} {ID, Namespace, ProviderName, Query...}
MSFT_NCProvAccessCheck {} {Namespace, ProviderName, Query, QueryLanguage...}
Win32_SystemTrace {} {SECURITY_DESCRIPTOR, TIME_CREATED}
Win32_ProcessTrace {} {ParentProcessID, ProcessID, ProcessName, SECURITY_DESCR...
< 省略 6gt;
Win32_PerfFormattedData_Workflow... {} {AverageWorkflowLoadTime, AverageWorkflowPersistTime, Ca...
Win32_PerfRawData_WorkflowServic... {} {AverageWorkflowLoadTime, AverageWorkflowLoadTime_Base, ...
Win32_PerfFormattedData_WSearchI... {} {ActiveConnections, Caption, CleanWidSets, Description...}
Win32_PerfRawData_WSearchIdxPi_S... {} {ActiveConnections, Caption, CleanWidSets, Description...}
955 WMI objects not contain CIM or __
上記を実行すると
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 でも、同様です。
[ 目次 ]
- $WMI = Get-WmiObject -List | Where-Object {$_.name -Match "network"}
次の事例を実行してみよう。
# PowerShell example to list demonstrate -Match
# Author: Guy Thomas
# Clear-Host
$WMI = Get-WmiObject -List | Where-Object {$_.name -Match "network"}
$WMI
Write-Host `n $WMI.count "WMI objects contain the word network."
WMI オブジェクトを取得して、Name に "network" が含まれるものを表示します。
6行目では、表示した個数を表示します。
それでは、実行してみましょう。下記のような結果が得られます。
NameSpace: ROOT\CIMV2
Name Methods Properties
---- ------- ----------
CIM_NetworkAdapter {SetPowerState, R... {AutoSense, Availability, Caption, ConfigManagerErrorCod...
Win32_NetworkAdapter {SetPowerState, R... {AdapterType, AdapterTypeId, AutoSense, Availability...}
Win32_NetworkConnection {} {AccessMask, Caption, Comment, ConnectionState...}
Win32_NetworkProtocol {} {Caption, ConnectionlessService, Description, Guarantees...
Win32_NetworkClient {} {Caption, Description, InstallDate, Manufacturer...}
Win32_NetworkAdapterConfiguration {EnableDHCP, Rene... {ArpAlwaysSourceRoute, ArpUseEtherSNAP, Caption, Databas...
Win32_NetworkLoginProfile {} {AccountExpires, AuthorizationFlags, BadPasswordCount, C...
Win32_NetworkAdapterSetting {} {Element, Setting}
Win32_SystemNetworkConnections {} {GroupComponent, PartComponent}
Win32_PerfFormattedData_Counters... {} {Bytestransmitted, BytestransmittedPersec, Caption, Desc...
Win32_PerfRawData_Counters_Netwo... {} {Bytestransmitted, BytestransmittedPersec, Caption, Desc...
Win32_PerfFormattedData_Counters... {} {BuildScatterGatherCyclesPersec, Caption, Description, F...
Win32_PerfRawData_Counters_PerPr... {} {BuildScatterGatherCyclesPersec, Caption, Description, F...
Win32_PerfFormattedData_Counters... {} {BuildScatterGatherListCallsPersec, Caption, Description...
Win32_PerfRawData_Counters_PerPr... {} {BuildScatterGatherListCallsPersec, Caption, Description...
Win32_PerfFormattedData_Counters... {} {Caption, Description, DevicePowerState, Frequency_Objec...
Win32_PerfRawData_Counters_Physi... {} {Caption, Description, DevicePowerState, Frequency_Objec...
Win32_PerfFormattedData_Counters... {} {BaseTCPRTT, BaseUDPRTT, Caption, CurrentTCPBandwidth...}
Win32_PerfRawData_Counters_Remot... {} {BaseTCPRTT, BaseUDPRTT, Caption, CurrentTCPBandwidth...}
Win32_PerfFormattedData_NETCLRNe... {} {BytesReceived, BytesSent, Caption, ConnectionsEstablish...
Win32_PerfRawData_NETCLRNetworki... {} {BytesReceived, BytesSent, Caption, ConnectionsEstablish...
Win32_PerfFormattedData_NETCLRNe... {} {BytesReceived, BytesSent, Caption, ConnectionsEstablish...
Win32_PerfRawData_NETCLRNetworki... {} {BytesReceived, BytesSent, Caption, ConnectionsEstablish...
Win32_PerfFormattedData_Tcpip_Ne... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
Win32_PerfRawData_Tcpip_NetworkA... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
Win32_PerfFormattedData_Tcpip_Ne... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
Win32_PerfRawData_Tcpip_NetworkI... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
27 WMI objects contain the word network.
上記を実行すると
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 でも、同様です。
[ 目次 ]
- $WMI = Get-WmiObject -List | Where-Object {$_.name -Like "*network"}
次の事例を実行してみよう。
# PowerShell example to demonstrate -Like
# Author: Guy Thomas
# Clear-Host
$WMI = Get-WmiObject -List | Where-Object {$_.name -Like "*network"}
$WMI
Write-Host `n $WMI.count "WMI objects contain the word network."
WMI オブジェクトを取得して、最後尾が "*network" であるものを表示します。
それでは、実行してみましょう。下記のような結果が得られます。
NameSpace: ROOT\CIMV2
Name Methods Properties
---- ------- ----------
Win32_PerfFormattedData_Counters... {} {BaseTCPRTT, BaseUDPRTT, Caption, CurrentTCPBandwidth...}
Win32_PerfRawData_Counters_Remot... {} {BaseTCPRTT, BaseUDPRTT, Caption, CurrentTCPBandwidth...}
2 WMI objects contain the word network.
上記を実行すると
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 でも、同様です。
[ 目次 ]
- $WMI = Get-WmiObject -List | Where-Object {$_.name -Like "*network*"}
次の事例を実行してみよう。
# PowerShell example to demonstrate -Like
# Author: Guy Thomas
# Clear-Host
$WMI = Get-WmiObject -List | Where-Object {$_.name -Like "*network*"}
$WMI
Write-Host `n $WMI.count "WMI objects contain the word network."
WMI オブジェクトを取得して、途中でも "*Adapter*" であるものを表示します。
結果は、前々項と同じです。
それでは、実行してみましょう。下記のような結果が得られます。
NameSpace: ROOT\CIMV2
Name Methods Properties
---- ------- ----------
CIM_NetworkAdapter {SetPowerState, R... {AutoSense, Availability, Caption, ConfigManagerErrorCod...
Win32_NetworkAdapter {SetPowerState, R... {AdapterType, AdapterTypeId, AutoSense, Availability...}
Win32_NetworkConnection {} {AccessMask, Caption, Comment, ConnectionState...}
Win32_NetworkProtocol {} {Caption, ConnectionlessService, Description, Guarantees...
Win32_NetworkClient {} {Caption, Description, InstallDate, Manufacturer...}
Win32_NetworkAdapterConfiguration {EnableDHCP, Rene... {ArpAlwaysSourceRoute, ArpUseEtherSNAP, Caption, Databas...
Win32_NetworkLoginProfile {} {AccountExpires, AuthorizationFlags, BadPasswordCount, C...
Win32_NetworkAdapterSetting {} {Element, Setting}
Win32_SystemNetworkConnections {} {GroupComponent, PartComponent}
Win32_PerfFormattedData_Counters... {} {Bytestransmitted, BytestransmittedPersec, Caption, Desc...
Win32_PerfRawData_Counters_Netwo... {} {Bytestransmitted, BytestransmittedPersec, Caption, Desc...
Win32_PerfFormattedData_Counters... {} {BuildScatterGatherCyclesPersec, Caption, Description, F...
Win32_PerfRawData_Counters_PerPr... {} {BuildScatterGatherCyclesPersec, Caption, Description, F...
Win32_PerfFormattedData_Counters... {} {BuildScatterGatherListCallsPersec, Caption, Description...
Win32_PerfRawData_Counters_PerPr... {} {BuildScatterGatherListCallsPersec, Caption, Description...
Win32_PerfFormattedData_Counters... {} {Caption, Description, DevicePowerState, Frequency_Objec...
Win32_PerfRawData_Counters_Physi... {} {Caption, Description, DevicePowerState, Frequency_Objec...
Win32_PerfFormattedData_Counters... {} {BaseTCPRTT, BaseUDPRTT, Caption, CurrentTCPBandwidth...}
Win32_PerfRawData_Counters_Remot... {} {BaseTCPRTT, BaseUDPRTT, Caption, CurrentTCPBandwidth...}
Win32_PerfFormattedData_NETCLRNe... {} {BytesReceived, BytesSent, Caption, ConnectionsEstablish...
Win32_PerfRawData_NETCLRNetworki... {} {BytesReceived, BytesSent, Caption, ConnectionsEstablish...
Win32_PerfFormattedData_NETCLRNe... {} {BytesReceived, BytesSent, Caption, ConnectionsEstablish...
Win32_PerfRawData_NETCLRNetworki... {} {BytesReceived, BytesSent, Caption, ConnectionsEstablish...
Win32_PerfFormattedData_Tcpip_Ne... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
Win32_PerfRawData_Tcpip_NetworkA... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
Win32_PerfFormattedData_Tcpip_Ne... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
Win32_PerfRawData_Tcpip_NetworkI... {} {BytesReceivedPersec, BytesSentPersec, BytesTotalPersec,...
27 WMI objects contain the word network.
上記を実行すると
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 でも、同様です。
[ 目次 ]
- If($_.name -Match "System") { Write-Host $($_.name) ; $i++ }
次の事例を実行してみよう。
# ----< -Match のサンプル >----
# Clear-Host
$i=0
Get-WmiObject -List | ForEach-Object {
If($_.name -Match "System") {
Write-Host $($_.name) ; $i++
}
}
"There are $i objects containing System"
WMI オブジェクトを取得しながら name に "System" が含まれるものを表示と個数をカウントします。
9行目では、オブジェクトの個数を表示しています。
それでは、実行してみましょう。下記のような結果が得られます。
__SystemClass
Win32_SystemConfigurationChangeEvent
Win32_SystemTrace
Win32_ComputerSystemEvent
MSFT_NetBootSystemDriversFailed
__SystemEvent
__SystemSecurity
CIM_ManagedSystemElement
CIM_OperatingSystem
Win32_OperatingSystem
< 省略 6gt;
Win32_PerfFormattedData_PerfOS_System
Win32_PerfRawData_PerfOS_System
Win32_PerfFormattedData_WindowsWorkflowFoundation4000_WFSystemWorkflow4000
Win32_PerfRawData_WindowsWorkflowFoundation4000_WFSystemWorkflow4000
There are 64 objects containing System
上記を実行すると
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 でも、同様です。
[ 目次 ]
- Where-Object {$_.name -NotMatch "CIM" -And $_.name -NotMatch "__"}
次の事例を実行してみよう。
# PowerShell example to list demonstrate -NotMatch and -And
# Author: Guy Thomas
# Clear-Host
$WMI = Get-WmiObject -List |`
Where-Object {$_.name -NotMatch "CIM" -And $_.name -NotMatch "__"}
$WMI
Write-Host `n $WMI.count "objects containing WMI, but not CIM or __"
WMI オブジェクトを取得して、Name に CIM も __ も含まれないものを表示します。
7行目では、表示したオブジェクトの個数を表示しています。
それでは、実行してみましょう。下記のような結果が得られます。
NameSpace: ROOT\cimv2
Name Methods Properties
---- ------- ----------
Win32_DeviceChangeEvent {} {EventType, SECURITY_DESCRIPTOR, TIME_CREATED}
Win32_SystemConfigurationChangeE... {} {EventType, SECURITY_DESCRIPTOR, TIME_CREATED}
Win32_VolumeChangeEvent {} {DriveName, EventType, SECURITY_DESCRIPTOR, TIME_CREATED}
MSFT_WMI_GenericNonCOMEvent {} {ProcessId, PropertyNames, PropertyValues, ProviderName...}
MSFT_NCProvEvent {} {Namespace, ProviderName, Result, SECURITY_DESCRIPTOR...}
MSFT_NCProvCancelQuery {} {ID, Namespace, ProviderName, Result...}
MSFT_NCProvClientConnected {} {Inproc, Namespace, ProviderName, Result...}
MSFT_NCProvNewQuery {} {ID, Namespace, ProviderName, Query...}
MSFT_NCProvAccessCheck {} {Namespace, ProviderName, Query, QueryLanguage...}
Win32_SystemTrace {} {SECURITY_DESCRIPTOR, TIME_CREATED}
Win32_ProcessTrace {} {ParentProcessID, ProcessID, ProcessName, SECURITY_DESCR...
< 省略 6gt;
Win32_PerfFormattedData_Workflow... {} {AverageWorkflowLoadTime, AverageWorkflowPersistTime, Ca...
Win32_PerfRawData_WorkflowServic... {} {AverageWorkflowLoadTime, AverageWorkflowLoadTime_Base, ...
Win32_PerfFormattedData_WSearchI... {} {ActiveConnections, Caption, CleanWidSets, Description...}
Win32_PerfRawData_WSearchIdxPi_S... {} {ActiveConnections, Caption, CleanWidSets, Description...}
953 objects containing WMI, but not CIM or __
上記を実行すると
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 でも、同様です。
[ 目次 ]
- $Guy -Match "\s"
次の事例を実行してみよう。
# -Match Character Class Example
$Guy ="Babe Ruth"
$Guy -Match "\s"
$Guy 変数にスペース文字が含まれるかを調べ結果を返します。
含まれている時には、True が、含まれていない時には、False が返します。
それでは、実行してみましょう。下記のような結果が得られます。
True
上記を実行すると
PowerShell 7.15 でも、正常(同様)に、実行されます。
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- [char[]]"rd2cp30" -Match "\d"
次の事例を実行してみよう。
# PowerShell example to extract numbers from a string
[char[]]"rd2cp30" -Match "\d"
文字列の内、数字(0-9) かを調べて、1文字毎に表示します。
それでは、実行してみましょう。下記のような結果が得られます。
2
3
0
上記を実行すると
PowerShell 7.15 でも、正常(同様)に、実行されます。
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- $ArraySimple -Contains "Flat"
次の事例を実行してみよう。
# PowerShell -Contains Operator
# Clear-Host
$ArraySimple =@("House","Flat","Bungalow")
$ArraySimple -Contains "Flat"
文字列配列中に、"Flat" と一致する要素があるかを調べます。
含まれている時には、True が、含まれていない時には、False が返します。
それでは、実行してみましょう。下記のような結果が得られます。
True
上記を実行すると
PowerShell 7.15 でも、正常(同様)に、実行されます。
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- $ArraySimple -Contains "Flat"( 2 / 2 )
次の事例を実行してみよう。
# PowerShell -Contains Operator
# Clear-Host
$ArraySimple =@("House","Flats","Bungalow")
$ArraySimple -Contains "Flat"
文字列配列中に、"Flat" と一致する要素があるかを調べます。
含まれている時には、True が、含まれていない時には、False が返します。
この事例では、"Flats" と "Flat" と s の有無で異なるので False が返されます。
それでは、実行してみましょう。下記のような結果が得られます。
False
上記を実行すると
PowerShell 7.15 でも、正常(同様)に、実行されます。
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- $Collection -Contains "Paula"( 不一致 )
次の事例を実行してみよう。
# PowerShell -Contains
$Collection = "Peter Smith", "Paula Harris", "Joan Evans"
$Collection -Contains "Paula"
文字列配列中に、"Paula" と一致する要素があるかを調べます。
含まれている時には、True が、含まれていない時には、False が返します。
この事例では、"Paula" と "Paula Harris" と s の有無で異なるので False が返されます。
それでは、実行してみましょう。下記のような結果が得られます。
False
上記を実行すると
PowerShell 7.15 でも、正常(同様)に、実行されます。
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- $Check = (Import-Csv $File)."name"; $Check -Contains "BFE"
次の事例を実行してみよう。
# PowerShell -Contains Operator
# Clear-Host
$File = ".\serviceslist2.csv"
$Check = (Import-Csv $File)."name"
$Check -Contains "BFE"
".\serviceslist2.csv" ファイルから "name" 列を取得して、"BFE" と一致するデータがあるかを調べます。
それでは、実行してみましょう。下記のような結果が得られます。
True
上記を実行すると
PowerShell 7.15 でも、正常(同様)に、実行されます。
PowerShell 7.4.6 でも、同様です。
[ 目次 ]
- $Check = (Import-Csv $File)."name"; $Check -NotContains "BFE"
次の事例を実行してみよう。
# PowerShell -Contains Operator
# Clear-Host
$File = ".\serviceslist2.csv"
$Check = (Import-Csv $File)."name"
$Check -NotContains "BFE"
".\serviceslist2.csv" ファイルから "name" 列を取得して、"BFE" と一致しないデータがあるかを調べます。
それでは、実行してみましょう。下記のような結果が得られます。
False
上記を実行すると
PowerShell 7.15 でも、正常(同様)に、実行されます。
PowerShell 7.4.6 でも、同様です。
|