Skip to content

Commit bd7af5d

Browse files
jborean93sdwheeler
andauthored
Add docs for new .NET MethodInvocation tracing (#12226)
* Add docs for new .NET MethodInvocation tracing Adds docs around the new .NET MethodInvocation tracing call introduced in PowerShell 7.6. This new tracing method allows you to see what method overload was invoked inside the tracing context. * Rebase and editorial changes --------- Co-authored-by: Sean Wheeler <sean.wheeler@microsoft.com>
1 parent 09eae68 commit bd7af5d

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

reference/7.6/Microsoft.PowerShell.Core/About/about_Methods.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes how to use methods to perform actions on objects in PowerShell.
33
Locale: en-US
4-
ms.date: 03/16/2022
4+
ms.date: 10/21/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_methods?view=powershell-7.6&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Methods
@@ -257,10 +257,57 @@ specific overload of the **Bar** method.
257257
int: 1
258258
```
259259

260+
## Finding which overload was used
261+
262+
Beginning in PowerShell 7.6, you can see which method overload PowerShell chose
263+
by using `MethodInvocation` tracing.
264+
265+
The following examples use `Trace-Command` to display the overload chosen when
266+
calling the [String.Split method](xref:System.String.Split%2A).
267+
268+
```powershell
269+
Trace-Command -PSHost -Name MethodInvocation -Expression {
270+
"a 1 b 1 c 1 d".Split(1)
271+
}
272+
```
273+
274+
In the first example, the integer `1` was converted to a `[char]` instead of a
275+
`[string]`, which results in string being split by `[char]1` instead of the
276+
string `"1"`.
277+
278+
```Output
279+
DEBUG: ... MethodInvocation Information: 0 : Invoking method: string[] Spli
280+
t(char separator, System.StringSplitOptions options = System.StringSplitOpt
281+
ions.None)
282+
283+
a 1 b 1 c 1 d
284+
```
285+
286+
In the second example, the `Split()` method is called with the string `"1"`.
287+
288+
```powershell
289+
Trace-Command -PSHost -Name MethodInvocation -Expression {
290+
"a 1 b 1 c 1 d".Split("1")
291+
}
292+
```
293+
294+
PowerShell chose the overload that takes a `[string]` separator.
295+
296+
```Output
297+
DEBUG: ... MethodInvocation Information: 0 : Invoking method: string[] Spli
298+
t(string separator, System.StringSplitOptions options = System.StringSplitO
299+
ptions.None)
300+
301+
a
302+
b
303+
c
304+
d
305+
```
306+
260307
## Using .NET methods that take filesystem paths
261308

262309
PowerShell supports multiple runspaces per process. Each runspace has its own
263-
_current directory_. This is not the same as the working directory of the
310+
_current directory_. This isn't the same as the working directory of the
264311
current process: `[System.Environment]::CurrentDirectory`.
265312

266313
.NET methods use the process working directory. PowerShell cmdlets use the
@@ -275,3 +322,4 @@ method.
275322
- [about_Member-Access_Enumeration](about_Member-Access_Enumeration.md)
276323
- [about_Properties](about_Properties.md)
277324
- [Get-Member](xref:Microsoft.PowerShell.Utility.Get-Member)
325+
- [Trace-Command](xref:Microsoft.PowerShell.Utility.Trace-Command)

0 commit comments

Comments
 (0)