天天看点

关于获取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

继续阅读