
上QQ阅读APP看书,第一时间看更新
How to do it…
- We will start by gathering the properties of our home directory. The path to this is stored in the automatic variable known as $HOME:
PS> Get-Item $HOME | Get-Member
Note the TypeName of the object—the very first line—as well as the MemberType column in the table.
- Next, check when the home directory was last written to:
PS> (Get-Item $HOME).LastWriteTime
- Can we find out when the parent of your $HOME was created?
PS> (Get-Item $HOME).Parent | Get-Member
PS> (Get-Item $HOME).Parent.CreationTime
To reiterate, PowerShell is not case-sensitive. However, to improve readability, we have stuck to the PowerShell convention of using camel case.
- What are the members of this object?
PS> (Get-Item $HOME).Parent.CreationTime | Get-Member
- Pick out the year:
PS> (Get-Item $HOME).Parent.CreationTime.Year
- Next, let's use a method from within the returned object and convert it into plain text. We saw that CreationTime is a DateTime object. Let's convert that into a plain string:
PS> (Get-Item $HOME).Parent.CreationTime.ToString()
- Find the type of object returned by the previous command. Press the up arrow key to bring back the previous command and pipe its output to Get-Member. Compare the output of Get-Member without .ToString():
PS> (Get-Item $HOME).Parent.CreationTime.ToString() | Get-Member
PS> (Get-Item $HOME).Parent.CreationTime | Get-Member