IT tutorials
 
Technology
 

Windows Server 2008 : Starting and Using PowerShell - Exploring get-member

12/26/2013 1:03:13 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

The get-member cmdlet shows what properties and events are available for a command. The following listing shows a partial output of the get-date | get-member command:

PS C:\ >get-date | get-member

TypeName: System.DateTime

Name MemberType Definition
---- ---------- ----------
Add Method System.DateTime Add(System.TimeSpan value)
AddDays Method System.DateTime AddDays(double value)
AddHours Method System.DateTime AddHours(double value)
. . .
ToShortDateString Method string ToShortDateString()
ToShortTimeString Method string ToShortTimeString()
. . .
Date Property System.DateTime Date {get;}
Day Property System.Int32 Day {get;}
DayOfWeek Property System.DayOfWeek DayOfWeek {get;}
DayOfYear Property System.Int32 DayOfYear {get;}
Hour Property System.Int32 Hour {get;}
Kind Property System.DateTimeKind Kind {get;}
Millisecond Property System.Int32 Millisecond {get;}
Minute Property System.Int32 Minute {get;}
Month Property System.Int32 Month {get;}
Second Property System.Int32 Second {get;}
Ticks Property System.Int64 Ticks {get;}
TimeOfDay Property System.TimeSpan TimeOfDay {get;}
Year Property System.Int32 Year {get;}


The following table shows how you can use this information retrieved with the get-member cmdlet by accessing properties or executing methods.

Note

Most properties and methods can be accessed using the dot operator, but the command must be in parentheses. The format is (command).property. As you can see, the dot operator is a period after the command. The following table includes some dot operator examples.


Exploring get-dateComments
Get available members.
PS C:\> get-date |
get-member

PS C:\> get-date |
get-member -force

This shows all of the members of the get-date cmdlet. The MemberType column identifies the members as methods and properties.

The Definition column identifies how the member can be used, such as {get;} to indicate a property can be retrieved, {set;} to indicate a property can be configured, or both.

The -force shows all members including intrinsic members.
Format member output to view definitions.
PS C:\> get-date |
get-member | format-
list

Displayed data often won’t fit on the screen and instead ends with an ellipsis (...). which usually simply means “there’s more.” You can use the format-list command to view all the data in a list format instead of a table format.
Retrieve a property using the dot operator.
(command). property
PS C:\>
(get-date).hour
19

Most properties can be retrieved simply by enclosing the cmdlet in parentheses and using a dot and the property name. The example shows the hour as 19 (or 7 PM) on a 24-hour clock.

Tip

This works when there is only one instance of a class. There is only one current date and time, so this works. It wouldn’t work for get-service because there are multiple instances of services running. The next table shows how to handle objects with multiple instances.

Execute a method with the dot operator.
(command).method()
PS C:\> (get-date).
toshorttimestring()
9:13 AM

Methods are executed with parentheses () at the end. Some methods accept (and require) parameters that can be included in the parentheses, but an empty parameter list often works.

Note

The get-member output shows that the toshorttimestring method has an empty parameter list in the description.

The example shows the output of the toshorttimestring method.
Execute a method with a parameter.
command.
method( parameter)
PS C:\> (get-date).
addhours(5).
toshorttimestring()
2:13 PM

The addhours() method requires a parameter and adds the provided number to the current hours.

Note

The get-member output shows that the addhours method requires a parameter of type double. Double is a number.

Notice that you can sometimes use more than one method by separating them with dots. The example adds five hours to the current time of 9:13 AM and then converts it to a short time string (such as 2:13 PM).

There is a difference in syntax when there’s just a single instance of an object and when there are multiple instances of an object. For example, the get-date cmdlet returns today’s date, and there is only one value of today’s date. However, there are always multiple services identified when you execute the get-service cmdlet.

Different procedures are required when you have multiple instances. The following table shows some examples.

Exploring get-serviceComments
Get available members.
PS C:\> get-service |
get-member

This shows all of the members of the get-service cmdlet. The MemberType column identifies the members as methods and properties. The Definition column identifies how the member can be used, such as {get;} to indicate a property can be retrieved.
Retrieve a property.
(command-name
name).property
(get-service -name
servicename).status
PS C:\ > (get-service
-name msftpsvc).status
Running

Properties of specific services can be retrieved using a unique identifier such as the name.

Note

The (get-service).status command returns a null value because it doesn’t know which service to query.

You can use the get-service command to identify the names of services to use with the -name switch.

The example checks the status of the FTP Publishing Service (msftpsvc). It returns running, stopped, or paused.
Execute a method.
(command -name
name).method()
PS C:\> (get-service
-name msftpsvc).stop()
PS C:\> (get-service
-name
msftpsvc).start()

Methods are executed with parentheses () at the end. Some methods accept parameters that can be included in the parentheses, but an empty parameter list often works.

Note

The output of get-service | get-member st* shows that the stop and start methods have empty parameter lists, as listed in the definition as Start() and Stop().

These examples show how to stop and start the FTP Publishing Service.
 
Others
 
- Windows Server 2008 : Starting and Using PowerShell - Creating Aliases, Discovering Windows PowerShell Commands
- Exchange Server 2010 : Managing Mailbox Databases (part 2) - Properties of a Mailbox Database
- Exchange Server 2010 : Managing Mailbox Databases (part 1) - Viewing Mailbox Databases, Creating Mailbox Databases
- Exchange Server 2010 : Mailbox Storage - Determining the Number of Databases, Allocating Disk Drives
- Exchange Server 2010 : Getting to Know Exchange Database Storage (part 2)
- Exchange Server 2010 : Getting to Know Exchange Database Storage (part 1)
- Understanding SharePoint 2013 authentication (part 3) - Understanding app authentication flow in SharePoint 2013
- Understanding SharePoint 2013 authentication (part 2) - Understanding how SharePoint 2013 authenticates apps
- Understanding SharePoint 2013 authentication (part 1) - Understanding user authentication in SharePoint 2013
- Sharepoint 2013 : Automating tasks with workflows - Importing Visio workflows into SharePoint Designer
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us