

Using Get-Member to Explore Objects
source link: https://thomasrayner.ca/using-get-member-to-explore-objects/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Using Get-Member to Explore Objects
Last week, I put out a post about using Select-Object to explore PowerShell objects. This week, I am going to quickly cover using Get-Member to do the same.
Let’s say you’re using Get-CimInstance to get information about the operating system. You might do something like this.
PS> Get-CimInstance -ClassName win32_operatingsystem
SystemDirectory Organization BuildNumber RegisteredUser SerialNumber Version
--------------- ------------ ----------- -------------- ------------ -------
C:\windows\system32 <snip> 14393 <snip> <snip> 10.0.14393
As is the case with our example last week, there’s more stuff returned and available to us than what is returned by default. Let’s use Get-Member to see what it all is.
PS> Get-CimInstance -ClassName win32_operatingsystem | get-member
TypeName: Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_OperatingSystem
Name MemberType Definition
---- ---------- ----------
Clone Method System.Object ICloneable.Clone()
Dispose Method void Dispose(), void IDisposable.Dispose()
Equals Method bool Equals(System.Object obj)
GetCimSessionComputerName Method string GetCimSessionComputerName()
GetCimSessionInstanceId Method guid GetCimSessionInstanceId()
GetHashCode Method int GetHashCode()
GetObjectData Method void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingCon... GetType Method type GetType()
ToString Method string ToString()
BootDevice Property string BootDevice {get;}
BuildNumber Property string BuildNumber {get;}
BuildType Property string BuildType {get;}
Caption Property string Caption {get;}
CodeSet Property string CodeSet {get;}
CountryCode Property string CountryCode {get;}
CreationClassName Property string CreationClassName {get;}
CSCreationClassName Property string CSCreationClassName {get;}
CSDVersion Property string CSDVersion {get;}
CSName Property string CSName {get;}
CurrentTimeZone Property int16 CurrentTimeZone {get;}
DataExecutionPrevention_32BitApplications Property bool DataExecutionPrevention_32BitApplications {get;}
DataExecutionPrevention_Available Property bool DataExecutionPrevention_Available {get;}
DataExecutionPrevention_Drivers Property bool DataExecutionPrevention_Drivers {get;}
DataExecutionPrevention_SupportPolicy Property byte DataExecutionPrevention_SupportPolicy {get;}
Debug Property bool Debug {get;}
Description Property string Description {get;set;}
Distributed Property bool Distributed {get;}
<output truncated>
Holy smokes, there’s a lot of stuff there. As with Select-Object, you can see all the different properties that exist in this object. The big difference here is that you can see all the different methods this object comes with, too. You could store this information in a variable and then invoke the .HashCode() on it and see the output of that, like this.
PS> $osInfo = Get-CimInstance -ClassName win32_operatingsystem
PS> $osInfo.GetHashCode()
57422975
There’s a lot of examples of methods that are more interesting than this, but you can play with it and make this work for you.
Recommend
-
36
Microsoft plans to explore using the Rust programming language as an alternative to C, C++, and others, as a way to improve the security posture of its and everyone else's apps.
-
8
overview of what we’re working on and how to explore apisPublished September 17, 2015 #happy_seed
-
4
The Difference Between Get-Member and .GetType() in PowerShell Recently, I was helping someone in a forum who was trying to figure out what kind of object their command was returning. They knew about the standard cmdlets...
-
9
Using Select-Object to Explore Objects When you’re first getting started with PowerShell, you may not be aware that sometimes when you run a command to get data, the information returned to the screen is not ALL the info...
-
12
Get All The Members Of The Distributions Lists That A User Is A Member Of This is kind of a weird script tip but I bumped into a need for this kind of script so I thought I’d share it. In this post, I have a user and I w...
-
8
How the Webb Telescope Will Explore Interstellar Objects
-
6
@astrodevilMr. ÅnandStudent | Content Creator | Explorer and Learner
-
4
Poco X5 series about to get a third member: GT certified
-
6
Researchers explore feasibility of using drones to survey sites for low levels of radiation by Allan Brettman,...
-
6
Taylor Hunt ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK