PowershellでWindowsServerのインベントリ情報を収集する
はじめに
PowershellでWindowsServerのインベントリ情報を収集する方法を纏めてみた。
動作確認環境は以下の通り。
- WindowsServer 2012R2
- Powershell 4.0
基本的にPowershellコマンドレットを用いた情報取得方法を記載するが、一部WMIオブジェクトを用いた方法も併せて記載した。
各コマンドレットを単に実行した場合、表示される情報は一部省略されてしまうため、すべての情報を表示したい場合は、"Format-List"コマンドレットに実行結果(PSオブジェクト)をパイプする必要がある。
PS > Get-NetIPAddress | Format-List *
ちなみに、Format-Listには"fl"というエイリアスが設定されているため、以下の様に実行しても同じ結果が得られる。
PS > Get-NetIPAddress | fl *
インベントリ情報収集
1. PSバージョン確認
PS > $PSVersionTable Name Value ---- ----- PSVersion 4.0 WSManStackVersion 3.0 SerializationVersion 1.1.0.1 CLRVersion 4.0.30319.34014 BuildVersion 6.3.9600.17090 PSCompatibleVersions {1.0, 2.0, 3.0, 4.0} PSRemotingProtocolVersion 2.2
2. PSプロバイダ一覧取得
PS > Get-PSProvider Name Capabilities Drives ---- ------------ ------ Alias ShouldProcess {Alias} Environment ShouldProcess {Env} FileSystem Filter, ShouldProcess, Credentials {C, D, A, Z} Function ShouldProcess {Function} Registry ShouldProcess, Transactions {HKLM, HKCU} Variable ShouldProcess {Variable}
3. エイリアス一覧取得
PS > Get-Alias CommandType Name ModuleName ----------- ---- ---------- Alias % -> ForEach-Object Alias ? -> Where-Object Alias ac -> Add-Content Alias asnp -> Add-PSSnapin Alias cat -> Get-Content Alias cd -> Set-Location Alias chdir -> Set-Location Alias clc -> Clear-Content ...
または、
PS > Get-ChildItem Alias:
4. 環境変数一覧取得
PS > Get-ChildItem env: Name Value ---- ----- ALLUSERSPROFILE C:\ProgramData APPDATA C:\Users\testuser01\AppData\Roaming CLIENTNAME testserver01 CommonProgramFiles C:\Program Files\Common Files CommonProgramFiles(x86) C:\Program Files (x86)\Common Files CommonProgramW6432 C:\Program Files\Common Files ...
5. 特殊変数一覧取得
PS > Get-ChildItem Variable: Name Value ---- ----- $ env: ? True ^ GEt-ChildItem args {} ConfirmPreference High ConsoleFileName DebugPreference SilentlyContinue ...
6. Windowsエディション取得
PS > Get-WindowsEdition -Online Edition : ServerStandard
または、
PS > Get-WmiObject Win32_OperatingSystem | % { $_.caption } Microsoft Windows Server 2012 R2 Standard
7. ローカルユーザアカウント一覧取得
PS > Get-WmiObject Win32_UserAccount | ? { $_.LocalAccount -eq $true } AccountType : 512 Caption : testserver01\Administrator Domain : testserver01 SID : S-1-5-21-1912470519-2430121858-3842388152-500 FullName : Name : Administrator ...
"$_.LocalAccount -eq $false"とすると、ドメインユーザアカウントが得られる。
8. ローカルグループアカウント一覧取得
PS > Get-WmiObject Win32_Group | ? { $_.LocalAccount -eq $true } Caption Domain Name SID ------- ------ ---- --- MP-NDMGS-MG01\Access Contr... testserver01 Access Control Assistance ... S-1-5-32-579 MP-NDMGS-MG01\Administrators testserver01 Administrators S-1-5-32-544 ...
"$_.LocalAccount -eq $false"とすると、ドメイングループアカウントが得られる。
9. コンピュータ名取得
PS > $env:COMPUTERNAME testserver01
11. ネットワークアダプタ一覧取得
PS > Get-NetAdapter Name InterfaceDescription ifIndex Status MacAddress LinkSpeed ---- -------------------- ------- ------ ---------- --------- Management vmxnet3 Ethernet Adapter #2 13 Up 00-50-56-B7-2D-36 1 Gbps Service vmxnet3 Ethernet Adapter 12 Up 00-50-56-B7-23-B2 1 Gbps ...
12. ネットワークアダプタ詳細設定取得
PS > Get-NetAdapterAdvancedProperty Name DisplayName DisplayValue RegistryKeyword RegistryValue ---- ----------- ------------ --------------- ------------- Management Interrupt Moderation Enabled *InterruptMo... {1} Management IPv4 Checksum Offload Rx & Tx Enabled *IPChecksumO... {3} Management Jumbo Packet Standard 1500 *JumboPacket {1514} Management IPv4 TSO Offload Enabled *LsoV1IPv4 {1} Management Large Send Offload V2 (IPv4) Enabled *LsoV2IPv4 {1} Management Large Send Offload V2 (IPv6) Enabled *LsoV2IPv6 {1} Management Maximum number of RSS Proce... -- *MaxRssProce... {--} Management Priority / VLAN tag Priority & VLAN Enabled *PriorityVLA... {3} Management Receive Side Scaling Disabled *RSS {0} Management RSS Base Processor Number -- *RssBaseProc... {--} Management Speed & Duplex 1.0 Gbps Full Duplex *SpeedDuplex {6} Management TCP Checksum Offload (IPv4) Rx & Tx Enabled *TCPChecksum... {3} Management TCP Checksum Offload (IPv6) Rx & Tx Enabled *TCPChecksum... {3} Management UDP Checksum Offload (IPv4) Rx & Tx Enabled *UDPChecksum... {3} Management UDP Checksum Offload (IPv6) Rx & Tx Enabled *UDPChecksum... {3} Management Wake on magic packet Enabled *WakeOnMagic... {1} Management Wake on pattern match Enabled *WakeOnPattern {1} Management Enable adaptive rx ring sizing Enabled EnableAdapti... {1} Management Wake-on-LAN Enabled EnableWakeOnLan {1} Management Rx Ring #1 Size -- MaxRxRing1Le... {--} Management Rx Ring #2 Size -- MaxRxRing2Le... {--} Management Max Tx Queues -- MaxTxQueues {--} Management Tx Ring Size -- MaxTxRingLength {--} Management MAC Address -- NetworkAddress {--} Management Large Rx Buffers -- NumRxBuffers... {--} Management Small Rx Buffers -- NumRxBuffers... {--} Management Offload IP Options Enabled OffloadIpOpt... {1} Management Offload TCP Options Enabled OffloadTcpOp... {1} Management Offload tagged traffic Enabled OffloadVlanE... {1} Management Receive Throttle -- RxThrottle {--} Management VLAN ID -- VlanId {--} ...
13. ネットワークアダプターバインディング取得
PS > Get-NetAdapterBinding Name DisplayName ComponentID Enabled ---- ----------- ----------- ------- Management Link-Layer Topology Discovery Responder ms_rspndr False Management Link-Layer Topology Discovery Mapper I/O Driver ms_lltdio False Management Microsoft Network Adapter Multiplexor Protocol ms_implat False Management Microsoft ネットワーク用クライアント ms_msclient True Management Microsoft Network Monitor 3 Driver ms_netmon True Management QoS パケット スケジューラ ms_pacer True Management Microsoft ネットワーク用ファイルとプリンター共有 ms_server True Management インターネット プロトコル バージョン 6 (TCP/IPv6) ms_tcpip6 False Management インターネット プロトコル バージョン 4 (TCP/IPv4) ms_tcpip True ...
14. IPアドレス一覧取得
PS > Get-NetIPAddress IPAddress : 192.168.0.1 InterfaceIndex : 13 InterfaceAlias : Management AddressFamily : IPv4 Type : Unicast PrefixLength : 16 PrefixOrigin : Manual SuffixOrigin : Manual AddressState : Preferred ValidLifetime : Infinite ([TimeSpan]::MaxValue) PreferredLifetime : Infinite ([TimeSpan]::MaxValue) SkipAsSource : False PolicyStore : ActiveStore ...
15. IP詳細設定取得
PS > Get-NetIpConfiguration InterfaceAlias : Management InterfaceIndex : 13 InterfaceDescription : vmxnet3 Ethernet Adapter #2 NetProfile.Name : 識別されていないネットワーク IPv4Address : 192.168.0.1 IPv4DefaultGateway : DNSServer : ...
16. ルーティングテーブル取得
PS > Get-NetRoute
または、
Get-WmiObject Win32_IP4RouteTable
18. 物理ディスク一覧取得
PS > Get-Disk Number Friendly Name OperationalStatus Total Size Partition Style ------ ------------- ----------------- ---------- --------------- 1 VMware Virtual disk SCSI Disk Device Online 200 GB MBR 0 VMware Virtual disk SCSI Disk Device Online 100 GB MBR ...
または、
PS > Get-PhysicalDisk FriendlyName CanPool OperationalStatus HealthStatus Usage Size ------------ ------- ----------------- ------------ ----- ---- PhysicalDisk1 False OK Healthy Auto-Select 200 GB PhysicalDisk0 False OK Healthy Auto-Select 100 GB ...
19. FWプロファイル取得
PS > Get-NetFirewallProfile Name : Domain Enabled : True DefaultInboundAction : NotConfigured DefaultOutboundAction : NotConfigured AllowInboundRules : NotConfigured AllowLocalFirewallRules : NotConfigured AllowLocalIPsecRules : NotConfigured AllowUserApps : NotConfigured AllowUserPorts : NotConfigured AllowUnicastResponseToMulticast : NotConfigured NotifyOnListen : False EnableStealthModeForIPsec : NotConfigured LogFileName : %systemroot%\system32\LogFiles\Firewall\pfirewall.log LogMaxSizeKilobytes : 4096 LogAllowed : False LogBlocked : False LogIgnored : NotConfigured DisabledInterfaceAliases : {NotConfigured} ...
20. FWポリシー一覧取得
PS > Get-NetFirewallRule
21. 役割と機能一覧取得
PS > Get-WindowsFeature Display Name Name Install State ------------ ---- ------------- [ ] Active Directory Federation Services ADFS-Federation Available [ ] Active Directory Rights Management サービス ADRMS Available [ ] Active Directory Rights Management サーバー ADRMS-Server Available [ ] ID フェデレーション サポート ADRMS-Identity Available ...
22. インストール済みアプリケーション一覧取得
PS > Get-WmiObject Win32_Product IdentifyingNumber : {26A24AE4-039D-4CA4-87B4-2F03217065FF} Name : Java 7 Update 65 Vendor : Oracle Version : 7.0.650 Caption : Java 7 Update 65 ...
23. サービス一覧取得
PS > Get-Service Status Name DisplayName ------ ---- ----------- Stopped AdtAgent Microsoft Monitoring Agent Audit Fo... ...
または、
PS > Get-WmiObject Win32_Service
24. Hotfix一覧取得
PS > Get-Hotfix Source Description HotFixID InstalledBy InstalledOn ------ ----------- -------- ----------- ----------- testserver01 Security Update KB2868626 testserver01\Adm... 2014/07/09 0:00:00 testserver01 Update KB2880289 NT AUTHORITY\SYSTEM 2014/09/11 0:00:00 ...