前一阵写了一个获取网络内主机类型的脚本,没有写任何解释类的说明直接发上来造成好多兄弟们有很多疑问。今天就拣几个有特点的功能说明一下。
获取windows系统或者性能参数。
在powershell出现之前系统管理员习惯用VB来实现获取以上参数的功能(当然现在也可以),但本次文章的重点主是说powershell怎么实现获取以上参数信息,Powershell提供了很多扩展的功能可以直接访问.net框架,WMI,COM自动化和API的调用等。
下面我们举例说明一哈通过WMI获取主机的内存信息:
1获取本地主机空余内存大小:
[PS] C:\>(GWMI win32_OperatingSystem).FreePhysicalMemory 1245384
2获取本地主机的总内存大小:
[PS] C:\>(GWMI win32_OperatingSystem).TotalVisibleMemorySize 4166596
3如果我们想查看还能查看还有哪些类可以获取,按如下操作就可以看到:
[PS] C:\>GWMI win32_OperatingSystem | Get-Member TypeName: System.Management.ManagementObject#root\cimv2\Win32_OperatingSystem Name MemberType Definition ---- ---------- ---------- Reboot Method System.Management.ManagementBaseObject Reboot() SetDateTime Method System.Management.ManagementBaseObject SetDateTime(System.String LocalDateTi Shutdown Method System.Management.ManagementBaseObject Shutdown() Win32Shutdown Method System.Management.ManagementBaseObject Win32Shutdown(System.Int32 Flags, Sys Win32ShutdownTracker Method System.Management.ManagementBaseObject Win32ShutdownTracker(System.UInt32 Ti BootDevice Property System.String BootDevice {get;set;} BuildNumber Property System.String BuildNumber {get;set;} BuildType Property System.String BuildType {get;set;} Caption Property System.String Caption {get;set;} CodeSet Property System.String CodeSet {get;set;} CountryCode Property System.String CountryCode {get;set;} CreationClassName Property System.String CreationClassName {get;set;} CSCreationClassName Property System.String CSCreationClassName {get;set;} CSDVersion Property System.String CSDVersion {get;set;} CSName Property System.String CSName {get;set;} CurrentTimeZone Property System.Int16 CurrentTimeZone {get;set;} DataExecutionPrevention_32BitApplications Property System.Boolean DataExecutionPrevention_32BitApplications {get;set;} DataExecutionPrevention_Available Property System.Boolean DataExecutionPrevention_Available {get;set;} DataExecutionPrevention_Drivers Property System.Boolean DataExecutionPrevention_Drivers {get;set;} DataExecutionPrevention_SupportPolicy Property System.Byte DataExecutionPrevention_SupportPolicy {get;set;} Debug Property System.Boolean Debug {get;set;} Description Property System.String Description {get;set;} Distributed Property System.Boolean Distributed {get;set;} EncryptionLevel Property System.UInt32 EncryptionLevel {get;set;} ForegroundApplicationBoost Property System.Byte ForegroundApplicationBoost {get;set;} FreePhysicalMemory Property System.UInt64 FreePhysicalMemory {get;set;} FreeSpaceInPagingFiles Property System.UInt64 FreeSpaceInPagingFiles {get;set;} FreeVirtualMemory Property System.UInt64 FreeVirtualMemory {get;set;} InstallDate Property System.String InstallDate {get;set;} LargeSystemCache Property System.UInt32 LargeSystemCache {get;set;} LastBootUpTime Property System.String LastBootUpTime {get;set;} LocalDateTime Property System.String LocalDateTime {get;set;} Locale Property System.String Locale {get;set;} Manufacturer Property System.String Manufacturer {get;set;} MaxNumberOfProcesses Property System.UInt32 MaxNumberOfProcesses {get;set;} MaxProcessMemorySize Property System.UInt64 MaxProcessMemorySize {get;set;} MUILanguages Property System.String[] MUILanguages {get;set;} Name Property System.String Name {get;set;} NumberOfLicensedUsers Property System.UInt32 NumberOfLicensedUsers {get;set;} NumberOfProcesses Property System.UInt32 NumberOfProcesses {get;set;} NumberOfUsers Property System.UInt32 NumberOfUsers {get;set;} OperatingSystemSKU Property System.UInt32 OperatingSystemSKU {get;set;} Organization Property System.String Organization {get;set;} OSArchitecture Property System.String OSArchitecture {get;set;} OSLanguage Property System.UInt32 OSLanguage {get;set;} OSProductSuite Property System.UInt32 OSProductSuite {get;set;} OSType Property System.UInt16 OSType {get;set;} OtherTypeDescription Property System.String OtherTypeDescription {get;set;} PAEEnabled Property System.Boolean PAEEnabled {get;set;} PlusProductID Property System.String PlusProductID {get;set;} PlusVersionNumber Property System.String PlusVersionNumber {get;set;} Primary Property System.Boolean Primary {get;set;} ProductType Property System.UInt32 ProductType {get;set;} RegisteredUser Property System.String RegisteredUser {get;set;} SerialNumber Property System.String SerialNumber {get;set;} ServicePackMajorVersion Property System.UInt16 ServicePackMajorVersion {get;set;} ServicePackMinorVersion Property System.UInt16 ServicePackMinorVersion {get;set;} SizeStoredInPagingFiles Property System.UInt64 SizeStoredInPagingFiles {get;set;} Status Property System.String Status {get;set;} SuiteMask Property System.UInt32 SuiteMask {get;set;} SystemDevice Property System.String SystemDevice {get;set;} SystemDirectory Property System.String SystemDirectory {get;set;} SystemDrive Property System.String SystemDrive {get;set;} TotalSwapSpaceSize Property System.UInt64 TotalSwapSpaceSize {get;set;} TotalVirtualMemorySize Property System.UInt64 TotalVirtualMemorySize {get;set;} TotalVisibleMemorySize Property System.UInt64 TotalVisibleMemorySize {get;set;} Version Property System.String Version {get;set;} WindowsDirectory Property System.String WindowsDirectory {get;set;} __CLASS Property System.String __CLASS {get;set;} __DERIVATION Property System.String[] __DERIVATION {get;set;} __DYNASTY Property System.String __DYNASTY {get;set;} __GENUS Property System.Int32 __GENUS {get;set;} __NAMESPACE Property System.String __NAMESPACE {get;set;} __PATH Property System.String __PATH {get;set;} __PROPERTY_COUNT Property System.Int32 __PROPERTY_COUNT {get;set;} __RELPATH Property System.String __RELPATH {get;set;} __SERVER Property System.String __SERVER {get;set;} __SUPERCLASS Property System.String __SUPERCLASS {get;set;} FREE PropertySet FREE {FreePhysicalMemory, FreeSpaceInPagingFiles, FreeVirtualMemory, Name} PSStatus PropertySet PSStatus {Status, Name} ConvertFromDateTime ScriptMethod System.Object ConvertFromDateTime(); ConvertToDateTime ScriptMethod System.Object ConvertToDateTime();
4 如果我们想获取远程主机的参数应该怎么操作呢只需加上-computer参数比如:
[PS] C:\>(GWMI -computer bjexfe01 win32_OperatingSystem).TotalVisibleMemorySize 33543988