天天看點

關于擷取windows系統參數方法

  前一陣寫了一個擷取網絡内主機類型的腳本,沒有寫任何解釋類的說明直接發上來造成好多兄弟們有很多疑問。今天就揀幾個有特點的功能說明一下。

   擷取windows系統或者性能參數。

   在powershell出現之前系統管理者習慣用VB來實作擷取以上參數的功能(當然現在也可以),但本次文章的重點主是說powershell怎麼實作擷取以上參數資訊,Powershell提供了很多擴充的功能可以直接通路.net架構,WMI,COM自動化和API的調用等。

   下面我們舉例說明一哈通過WMI擷取主機的記憶體資訊:

   1擷取本地主機空餘記憶體大小:

1

2

<code>[PS]</code> <code>C:\&gt;(GWMI win32_OperatingSystem).FreePhysicalMemory</code>

<code>1245384</code>

   2擷取本地主機的總記憶體大小:

<code>[PS]</code> <code>C:\&gt;(GWMI win32_OperatingSystem).TotalVisibleMemorySize</code>

<code>4166596</code>

   3如果我們想檢視還能檢視還有哪些類可以擷取,按如下操作就可以看到:

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

<code>[PS]</code> <code>C:\&gt;GWMI win32_OperatingSystem | </code><code>Get-Member</code>

<code>   </code><code>TypeName: System.Management.ManagementObject</code><code>#root\cimv2\Win32_OperatingSystem</code>

<code>Name                                      MemberType   Definition</code>

<code>----                                      ----------   ----------</code>

<code>Reboot                                    Method       System.Management.ManagementBaseObject Reboot()</code>

<code>SetDateTime                               Method       System.Management.ManagementBaseObject SetDateTime(System.String LocalDateTi</code>

<code>Shutdown                                  Method       System.Management.ManagementBaseObject Shutdown()</code>

<code>Win32Shutdown                             Method       System.Management.ManagementBaseObject Win32Shutdown(System.Int32 Flags, Sys</code>

<code>Win32ShutdownTracker                      Method       System.Management.ManagementBaseObject Win32ShutdownTracker(System.UInt32 Ti</code>

<code>BootDevice                                Property     System.String BootDevice {get;set;}</code>

<code>BuildNumber                               Property     System.String BuildNumber {get;set;}</code>

<code>BuildType                                 Property     System.String BuildType {get;set;}</code>

<code>Caption                                   Property     System.String Caption {get;set;}</code>

<code>CodeSet                                   Property     System.String CodeSet {get;set;}</code>

<code>CountryCode                               Property     System.String CountryCode {get;set;}</code>

<code>CreationClassName                         Property     System.String CreationClassName {get;set;}</code>

<code>CSCreationClassName                       Property     System.String CSCreationClassName {get;set;}</code>

<code>CSDVersion                                Property     System.String CSDVersion {get;set;}</code>

<code>CSName                                    Property     System.String CSName {get;set;}</code>

<code>CurrentTimeZone                           Property     System.Int16 CurrentTimeZone {get;set;}</code>

<code>DataExecutionPrevention_32BitApplications Property     System.Boolean DataExecutionPrevention_32BitApplications {get;set;}</code>

<code>DataExecutionPrevention_Available         Property     System.Boolean DataExecutionPrevention_Available {get;set;}</code>

<code>DataExecutionPrevention_Drivers           Property     System.Boolean DataExecutionPrevention_Drivers {get;set;}</code>

<code>DataExecutionPrevention_SupportPolicy     Property     System.Byte DataExecutionPrevention_SupportPolicy {get;set;}</code>

<code>Debug                                     Property     System.Boolean Debug {get;set;}</code>

<code>Description                               Property     System.String Description {get;set;}</code>

<code>Distributed                               Property     System.Boolean Distributed {get;set;}</code>

<code>EncryptionLevel                           Property     System.UInt32 EncryptionLevel {get;set;}</code>

<code>ForegroundApplicationBoost                Property     System.Byte ForegroundApplicationBoost {get;set;}</code>

<code>FreePhysicalMemory                        Property     System.UInt64 FreePhysicalMemory {get;set;}</code>

<code>FreeSpaceInPagingFiles                    Property     System.UInt64 FreeSpaceInPagingFiles {get;set;}</code>

<code>FreeVirtualMemory                         Property     System.UInt64 FreeVirtualMemory {get;set;}</code>

<code>InstallDate                               Property     System.String InstallDate {get;set;}</code>

<code>LargeSystemCache                          Property     System.UInt32 LargeSystemCache {get;set;}</code>

<code>LastBootUpTime                            Property     System.String LastBootUpTime {get;set;}</code>

<code>LocalDateTime                             Property     System.String LocalDateTime {get;set;}</code>

<code>Locale                                    Property     System.String Locale {get;set;}</code>

<code>Manufacturer                              Property     System.String Manufacturer {get;set;}</code>

<code>MaxNumberOfProcesses                      Property     System.UInt32 MaxNumberOfProcesses {get;set;}</code>

<code>MaxProcessMemorySize                      Property     System.UInt64 MaxProcessMemorySize {get;set;}</code>

<code>MUILanguages                              Property     System.String[] MUILanguages {get;set;}</code>

<code>Name                                      Property     System.String Name {get;set;}</code>

<code>NumberOfLicensedUsers                     Property     System.UInt32 NumberOfLicensedUsers {get;set;}</code>

<code>NumberOfProcesses                         Property     System.UInt32 NumberOfProcesses {get;set;}</code>

<code>NumberOfUsers                             Property     System.UInt32 NumberOfUsers {get;set;}</code>

<code>OperatingSystemSKU                        Property     System.UInt32 OperatingSystemSKU {get;set;}</code>

<code>Organization                              Property     System.String Organization {get;set;}</code>

<code>OSArchitecture                            Property     System.String OSArchitecture {get;set;}</code>

<code>OSLanguage                                Property     System.UInt32 OSLanguage {get;set;}</code>

<code>OSProductSuite                            Property     System.UInt32 OSProductSuite {get;set;}</code>

<code>OSType                                    Property     System.UInt16 OSType {get;set;}</code>

<code>OtherTypeDescription                      Property     System.String OtherTypeDescription {get;set;}</code>

<code>PAEEnabled                                Property     System.Boolean PAEEnabled {get;set;}</code>

<code>PlusProductID                             Property     System.String PlusProductID {get;set;}</code>

<code>PlusVersionNumber                         Property     System.String PlusVersionNumber {get;set;}</code>

<code>Primary                                   Property     System.Boolean Primary {get;set;}</code>

<code>ProductType                               Property     System.UInt32 ProductType {get;set;}</code>

<code>RegisteredUser                            Property     System.String RegisteredUser {get;set;}</code>

<code>SerialNumber                              Property     System.String SerialNumber {get;set;}</code>

<code>ServicePackMajorVersion                   Property     System.UInt16 ServicePackMajorVersion {get;set;}</code>

<code>ServicePackMinorVersion                   Property     System.UInt16 ServicePackMinorVersion {get;set;}</code>

<code>SizeStoredInPagingFiles                   Property     System.UInt64 SizeStoredInPagingFiles {get;set;}</code>

<code>Status                                    Property     System.String Status {get;set;}</code>

<code>SuiteMask                                 Property     System.UInt32 SuiteMask {get;set;}</code>

<code>SystemDevice                              Property     System.String SystemDevice {get;set;}</code>

<code>SystemDirectory                           Property     System.String SystemDirectory {get;set;}</code>

<code>SystemDrive                               Property     System.String SystemDrive {get;set;}</code>

<code>TotalSwapSpaceSize                        Property     System.UInt64 TotalSwapSpaceSize {get;set;}</code>

<code>TotalVirtualMemorySize                    Property     System.UInt64 TotalVirtualMemorySize {get;set;}</code>

<code>TotalVisibleMemorySize                    Property     System.UInt64 TotalVisibleMemorySize {get;set;}</code>

<code>Version                                   Property     System.String Version {get;set;}</code>

<code>WindowsDirectory                          Property     System.String WindowsDirectory {get;set;}</code>

<code>__CLASS                                   Property     System.String __CLASS {get;set;}</code>

<code>__DERIVATION                              Property     System.String[] __DERIVATION {get;set;}</code>

<code>__DYNASTY                                 Property     System.String __DYNASTY {get;set;}</code>

<code>__GENUS                                   Property     System.Int32 __GENUS {get;set;}</code>

<code>__NAMESPACE                               Property     System.String __NAMESPACE {get;set;}</code>

<code>__PATH                                    Property     System.String __PATH {get;set;}</code>

<code>__PROPERTY_COUNT                          Property     System.Int32 __PROPERTY_COUNT {get;set;}</code>

<code>__RELPATH                                 Property     System.String __RELPATH {get;set;}</code>

<code>__SERVER                                  Property     System.String __SERVER {get;set;}</code>

<code>__SUPERCLASS                              Property     System.String __SUPERCLASS {get;set;}</code>

<code>FREE                                      PropertySet  FREE {FreePhysicalMemory, FreeSpaceInPagingFiles, FreeVirtualMemory, Name}</code>

<code>PSStatus                                  PropertySet  PSStatus {Status, Name}</code>

<code>ConvertFromDateTime                       ScriptMethod System.Object ConvertFromDateTime();</code>

<code>ConvertToDateTime                         ScriptMethod System.Object ConvertToDateTime();</code>

  4 如果我們想擷取遠端主機的參數應該怎麼操作呢隻需加上-computer參數比如:

<code>[PS]</code> <code>C:\&gt;(GWMI</code> <code>-computer</code> <code>bjexfe01  win32_OperatingSystem).TotalVisibleMemorySize</code>

<code>33543988</code>

本文轉自handsome7038 51CTO部落格,原文連結:http://blog.51cto.com/lixiaosong/1357271

繼續閱讀