# 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 November 10, 2026

## 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:

```powershell
(Get-Item sunset.jpg).Length
```

```text
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:

```powershell
(Get-Item sunset.jpg).LastWriteTime
(Get-Item sunset.jpg).Extension
```

```text
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:

```powershell
(Get-Item sunset.jpg).LastWriteTime.DayOfWeek
```

```text
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:

```powershell
'beach day'.ToUpper()
(Get-Item sunset.jpg).Name.ToUpper()
```

```text
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:

```powershell
'beach day' | Get-Member -Name ToUpper, Length
```

```text
   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:

```powershell
'beach day'.ToUpper
```

```text
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:

```powershell
Get-Date
(Get-Date).AddDays(-7)
```

```text
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:

```powershell
(Get-Item sunset.jpg).LastWriteTime.AddDays(-7)
```

```text
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:

```powershell
(Get-Process -Id $PID).StartTime
```

```text
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.

## Key terms

- [Property](https://www.ask-codey.com/glossary/property-oop)
- [Method](https://www.ask-codey.com/glossary/method-oop)
- [Get-Date](https://www.ask-codey.com/glossary/get-date)
- [Get-Process](https://www.ask-codey.com/glossary/get-process)

## Cheat sheets

- [Properties and Methods](https://www.ask-codey.com/cheat-sheets/powershell-properties-and-methods-cheat-sheet)

## Related

- [What an Object Is: Get-Member](https://www.ask-codey.com/lessons/powershell-what-is-an-object)
- [Picking Columns: Select-Object](https://www.ask-codey.com/lessons/powershell-select-object)

Source: https://www.ask-codey.com/lessons/powershell-properties-and-methods
