Properties and Methods
A dot after an object reads one of its properties, such as a file's Length or LastWriteTime, and a dot with parentheses runs one of its methods, something the object can do, such as ToUpper() or AddDays(-7).
Apprentice · PowerShell · Updated
After this lesson you can
- Read one property of an object with a dot, such as (Get-Item sunset.jpg).Length
- Call a method with parentheses, such as .ToUpper() or .AddDays(-7), and tell a method from a property
Key takeaways
- Put a command in parentheses and add a dot and a property's name to get that one fact:
(Get-Item sunset.jpg).Length. - A property can be an object too, so dots can go on, as in
.LastWriteTime.DayOfWeek. - A method is something an object can do. Its name is followed by parentheses, such as
.ToUpper(). .AddDays(-7)gives the date a week earlier. The value in the parentheses is what the method works with.- A misspelled property name prints nothing, with no error, so check the name with Get-Member.
A friend asks how big the sunset photo is before you email it. A form wants the date your receipt was saved. You want to know what the date was a week ago, so you can find the photos from last weekend, and counting back on a calendar across the end of a month is how mistakes happen. Each time you need one fact, not a whole table. PowerShell can hand you that one fact, and it can work things out for you, like the date a week ago. A script that backs up last week's files, which Module 6 teaches you to write, is built from exactly these two moves.
This lesson uses the vacation-photos folder from What an Object Is: Get-Member. If you don't have it, run that lesson's practice-folder lines first; they leave you inside the folder.
One fact: the dot
Back to the library. The card for your book has its due date on it, and when you want only that, you look at that one line. In PowerShell the line you want is a property, and a dot gets it:
(Get-Item sunset.jpg).Length
3150
Read it from the left. The parentheses say "do this first": get the file. The dot then reads one property of the object that came out, so read .Length as "'s length": the sunset photo's length, 3,150 bytes. The answer is the number itself, with no table around it.
Any property Get-Member listed works the same way:
(Get-Item sunset.jpg).LastWriteTime
(Get-Item sunset.jpg).Extension
Saturday, July 18, 2026 9:40:00 PM
.jpg
Your date will be when you made the file. Capital letters don't matter in a property's name: .length works too. Spelling does. Ask for a property the object doesn't have, such as (Get-Item sunset.jpg).Size, and PowerShell prints nothing at all, not even an error. A file's size is called Length, not Size. When a property prints nothing, check its name with Get-Member.
A fact that has facts of its own
LastWriteTime isn't text either. Its Definition in Get-Member said datetime, so it's a date object, with properties of its own, such as DayOfWeek. Add another dot:
(Get-Item sunset.jpg).LastWriteTime.DayOfWeek
Saturday
Read the dots from left to right: the file, its last write time, that date's day of the week. No calendar needed.
Things an object can do: methods
A library loan has facts, and it can also do something: you can renew it, and the due date moves. Things an object can do are its methods. You call a method with a dot, its name and parentheses, (). Text is an object too (a string), and one of the things it can do is give you itself in capital letters:
'beach day'.ToUpper()
(Get-Item sunset.jpg).Name.ToUpper()
BEACH DAY
SUNSET.JPG
The parentheses are how you tell the two apart. A property is a fact, so it has none: .Length. A method is an action, so it always has them: .ToUpper(). Get-Member says which is which, in its MemberType column:
'beach day' | Get-Member -Name ToUpper, Length
TypeName: System.String
Name MemberType Definition
---- ---------- ----------
ToUpper Method string ToUpper(), string ToUpper(cultureinfo culture)
Length Property int Length {get;}
Forget the parentheses, and PowerShell doesn't run the method; it shows you its description instead:
'beach day'.ToUpper
OverloadDefinitions
-------------------
string ToUpper()
string ToUpper(cultureinfo culture)
If you see OverloadDefinitions, add the ().
Dates: a week ago with AddDays(-7)
Some methods need something to work with, and it goes inside the parentheses. A date's AddDays method takes a number of days; -7 (read "minus seven") goes back a week. Get-Date gets the date and time right now:
Get-Date
(Get-Date).AddDays(-7)
Monday, November 9, 2026 4:48:50 AM
Monday, November 2, 2026 4:48:50 AM
Yours shows your own date and time. AddDays crosses the end of a month or a year for you, and it changes nothing: it gives you a new date and leaves the old one as it was. It works on any date, the photo's too:
(Get-Item sunset.jpg).LastWriteTime.AddDays(-7)
Saturday, July 11, 2026 9:40:00 PM
Running programs work the same way. (Get-Process -Id $PID).StartTime is when the PowerShell window you're typing in started:
(Get-Process -Id $PID).StartTime
Monday, November 9, 2026 4:48:49 AM
Everything in this lesson works the same in Windows PowerShell 5.1, and on a Mac or Linux.
Try it. How many letters long is the name sunset.jpg? The name is a string, and a string has a Length too: (Get-Item sunset.jpg).Name.Length. Then find the day of the week 30 days from now with (Get-Date).AddDays(30).DayOfWeek.
Check yourself
2 questions to try on the lesson page.
So what
A dot reads a fact, and a dot with parentheses does something. With those two, any object PowerShell gives you can answer a question or work out a new value, which is most of what a script does.