How it works...

Accessing members of a class, whether they are properties or methods, is usually achieved through dot notation. In the case of methods, a pair of parentheses is also necessary. Please note that there should not be any whitespace characters between the method name and the parentheses.

You started off in Step 1 by using Get-Member to discover properties and methods. Executing a method is different from accessing a property. Method calls always require parentheses and can optionally accept parameters. You did this in Step 2 by using the MoveTo method with arguments and the Delete method without arguments.

As you saw in Step 1there are plenty of methods to choose from. Some methods you will encounter will have more than one way of calling it. These are called overloads. The CopyTo method of a file, for example, allows you to specify either the file path or the file path and a Boolean flag, indicating whether the destination will be overwritten. In Step 4, you used Get-Member as well as dot notation to see method definitions.

Method calls can improve your script performance, sometimes significantly. Unfortunately, this doesn't mean that your code will be more readable. In Step 5, you tried two different methods of listing files to see the difference between native PowerShell and .NET.

If a method accepts arguments, they are inserted into parentheses, separated by a comma. Even when calling .NET methods, PowerShell will attempt to convert your arguments into the correct data types if possible. Use parentheses to form expressions if you are using the return value of a cmdlet as input, as follows:

$process.WaitForExit($(New-TimeSpan -Seconds 30).TotalMilliseconds)