Skip to content

Commit dad3025

Browse files
authored
Add notes about CIM/CDXML bugs with PipelineVariable (#12026)
1 parent fe785b5 commit dad3025

File tree

4 files changed

+275
-4
lines changed

4 files changed

+275
-4
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_CommonParameters.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the parameters that can be used with any cmdlet.
33
Locale: en-US
4-
ms.date: 07/02/2024
4+
ms.date: 04/24/2025
55
no-loc: [Debug, Verbose, Confirm]
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-5.1&WT.mc_id=ps-gethelp
77
schema: 2.0.0
@@ -471,6 +471,64 @@ At line:1 char:1
471471
+ FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.GetVariableCommand
472472
```
473473

474+
> [!CAUTION]
475+
> There are two known issues with using the **PipelineVariable** parameter in a
476+
> pipeline that includes CimCmdlets or CDXML cmdlets. In the following
477+
> examples, `Get-Partition` is a CDXML function and `Get-CimInstance` is a
478+
> CimCmdlet.
479+
480+
1. CDXML functions use `[CmdletBinding()]`, which allows the
481+
**PipelineVariable** parameter.
482+
483+
```powershell
484+
Get-Partition -pv pvar
485+
```
486+
487+
However, when you use **PipelineVariable** in Windows PowerShell v5.1, you
488+
receive the following error.
489+
490+
```Output
491+
Get-Partition : Cannot retrieve the dynamic parameters for the cmdlet.
492+
Object reference not set to an instance of an object.
493+
494+
At line:1 char:1
495+
+ get-partition -PipelineVariable pvar
496+
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
497+
+ CategoryInfo : InvalidArgument: (:) [Get-Partition], ParameterBindingException
498+
+ FullyQualifiedErrorId : GetDynamicParametersException,Get-Partition
499+
```
500+
501+
1. When the preceding command is _not_ a CDXML command and the downstream
502+
contains either command type, the **PipelineVariable** remains as the last
503+
accumulated object.
504+
505+
```powershell
506+
Get-CimInstance Win32_DiskDrive -pv pvar |
507+
ForEach-Object {
508+
Write-Host "Before: $($pvar.Index)"
509+
[pscustomobject]@{ DiskNumber = $_.Index }
510+
} |
511+
Get-Partition |
512+
ForEach-Object {
513+
Write-Host "After: $($pvar.Index)"
514+
}
515+
```
516+
517+
Notice that the value of `$pvar` set to the last object in the pipeline for
518+
the second `ForEach-Object` command.
519+
520+
```Output
521+
Before: 1
522+
Before: 2
523+
Before: 0
524+
After: 0
525+
After: 0
526+
After: 0
527+
After: 0
528+
After: 0
529+
After: 0
530+
```
531+
474532
### -ProgressAction
475533

476534
Determines how PowerShell responds to progress updates generated by a script,

reference/7.4/Microsoft.PowerShell.Core/About/about_CommonParameters.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the parameters that can be used with any cmdlet.
33
Locale: en-US
4-
ms.date: 07/02/2024
4+
ms.date: 04/24/2025
55
no-loc: [Debug, Verbose, Confirm]
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7.4&WT.mc_id=ps-gethelp
77
schema: 2.0.0
@@ -459,6 +459,77 @@ Name Value
459459
temp
460460
```
461461

462+
> [!CAUTION]
463+
> There are two known issues with using the **PipelineVariable** parameter in a
464+
> pipeline that includes CimCmdlets or CDXML cmdlets. In the following
465+
> examples, `Get-Partition` is a CDXML function and `Get-CimInstance` is a
466+
> CimCmdlet.
467+
468+
1. When the first command is a CDXML function and downstream contains either a
469+
CimCmdlet cmdlet or CDXML function, **PipelineVariable** is reset to
470+
`$null`.
471+
472+
```powershell
473+
Get-Partition -pv pvar |
474+
ForEach-Object {
475+
Write-Host "Before: $($pvar.PartitionNumber)"
476+
[pscustomobject]@{Filter = "Index = $($_.DiskNumber)"}
477+
} |
478+
Get-CimInstance Win32_DiskDrive |
479+
ForEach-Object {
480+
Write-Host "After: $($pvar.PartitionNumber)"
481+
}
482+
```
483+
484+
Notice that the value of `$pvar` set to `$null` in the pipeline for the
485+
second `ForEach-Object` command.
486+
487+
```Output
488+
Before: 1
489+
Before: 1
490+
Before: 2
491+
Before: 3
492+
Before: 4
493+
Before: 1
494+
After:
495+
After:
496+
After:
497+
After:
498+
After:
499+
After:
500+
```
501+
502+
1. When the preceding command is _not_ a CDXML command and the downstream
503+
contains either command type, the **PipelineVariable** remains as the last
504+
accumulated object.
505+
506+
```powershell
507+
Get-CimInstance Win32_DiskDrive -pv pvar |
508+
ForEach-Object {
509+
Write-Host "Before: $($pvar.Index)"
510+
[pscustomobject]@{ DiskNumber = $_.Index }
511+
} |
512+
Get-Partition |
513+
ForEach-Object {
514+
Write-Host "After: $($pvar.Index)"
515+
}
516+
```
517+
518+
Notice that the value of `$pvar` set to the last object in the pipeline for
519+
the second `ForEach-Object` command.
520+
521+
```Output
522+
Before: 1
523+
Before: 2
524+
Before: 0
525+
After: 0
526+
After: 0
527+
After: 0
528+
After: 0
529+
After: 0
530+
After: 0
531+
```
532+
462533
### -ProgressAction
463534

464535
Determines how PowerShell responds to progress updates generated by a script,

reference/7.5/Microsoft.PowerShell.Core/About/about_CommonParameters.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the parameters that can be used with any cmdlet.
33
Locale: en-US
4-
ms.date: 07/02/2024
4+
ms.date: 04/24/2025
55
no-loc: [Debug, Verbose, Confirm]
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7.5&WT.mc_id=ps-gethelp
77
schema: 2.0.0
@@ -459,6 +459,77 @@ Name Value
459459
temp
460460
```
461461

462+
> [!CAUTION]
463+
> There are two known issues with using the **PipelineVariable** parameter in a
464+
> pipeline that includes CimCmdlets or CDXML cmdlets. In the following
465+
> examples, `Get-Partition` is a CDXML function and `Get-CimInstance` is a
466+
> CimCmdlet.
467+
468+
1. When the first command is a CDXML function and downstream contains either a
469+
CimCmdlet cmdlet or CDXML function, **PipelineVariable** is reset to
470+
`$null`.
471+
472+
```powershell
473+
Get-Partition -pv pvar |
474+
ForEach-Object {
475+
Write-Host "Before: $($pvar.PartitionNumber)"
476+
[pscustomobject]@{Filter = "Index = $($_.DiskNumber)"}
477+
} |
478+
Get-CimInstance Win32_DiskDrive |
479+
ForEach-Object {
480+
Write-Host "After: $($pvar.PartitionNumber)"
481+
}
482+
```
483+
484+
Notice that the value of `$pvar` set to `$null` in the pipeline for the
485+
second `ForEach-Object` command.
486+
487+
```Output
488+
Before: 1
489+
Before: 1
490+
Before: 2
491+
Before: 3
492+
Before: 4
493+
Before: 1
494+
After:
495+
After:
496+
After:
497+
After:
498+
After:
499+
After:
500+
```
501+
502+
1. When the preceding command is _not_ a CDXML command and the downstream
503+
contains either command type, the **PipelineVariable** remains as the last
504+
accumulated object.
505+
506+
```powershell
507+
Get-CimInstance Win32_DiskDrive -pv pvar |
508+
ForEach-Object {
509+
Write-Host "Before: $($pvar.Index)"
510+
[pscustomobject]@{ DiskNumber = $_.Index }
511+
} |
512+
Get-Partition |
513+
ForEach-Object {
514+
Write-Host "After: $($pvar.Index)"
515+
}
516+
```
517+
518+
Notice that the value of `$pvar` set to the last object in the pipeline for
519+
the second `ForEach-Object` command.
520+
521+
```Output
522+
Before: 1
523+
Before: 2
524+
Before: 0
525+
After: 0
526+
After: 0
527+
After: 0
528+
After: 0
529+
After: 0
530+
After: 0
531+
```
532+
462533
### -ProgressAction
463534

464535
Determines how PowerShell responds to progress updates generated by a script,

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

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the parameters that can be used with any cmdlet.
33
Locale: en-US
4-
ms.date: 07/02/2024
4+
ms.date: 04/24/2025
55
no-loc: [Debug, Verbose, Confirm]
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7.6&WT.mc_id=ps-gethelp
77
schema: 2.0.0
@@ -459,6 +459,77 @@ Name Value
459459
temp
460460
```
461461

462+
> [!CAUTION]
463+
> There are two known issues with using the **PipelineVariable** parameter in a
464+
> pipeline that includes CimCmdlets or CDXML cmdlets. In the following
465+
> examples, `Get-Partition` is a CDXML function and `Get-CimInstance` is a
466+
> CimCmdlet.
467+
468+
1. When the first command is a CDXML function and downstream contains either a
469+
CimCmdlet cmdlet or CDXML function, **PipelineVariable** is reset to
470+
`$null`.
471+
472+
```powershell
473+
Get-Partition -pv pvar |
474+
ForEach-Object {
475+
Write-Host "Before: $($pvar.PartitionNumber)"
476+
[pscustomobject]@{Filter = "Index = $($_.DiskNumber)"}
477+
} |
478+
Get-CimInstance Win32_DiskDrive |
479+
ForEach-Object {
480+
Write-Host "After: $($pvar.PartitionNumber)"
481+
}
482+
```
483+
484+
Notice that the value of `$pvar` set to `$null` in the pipeline for the
485+
second `ForEach-Object` command.
486+
487+
```Output
488+
Before: 1
489+
Before: 1
490+
Before: 2
491+
Before: 3
492+
Before: 4
493+
Before: 1
494+
After:
495+
After:
496+
After:
497+
After:
498+
After:
499+
After:
500+
```
501+
502+
1. When the preceding command is _not_ a CDXML command and the downstream
503+
contains either command type, the **PipelineVariable** remains as the last
504+
accumulated object.
505+
506+
```powershell
507+
Get-CimInstance Win32_DiskDrive -pv pvar |
508+
ForEach-Object {
509+
Write-Host "Before: $($pvar.Index)"
510+
[pscustomobject]@{ DiskNumber = $_.Index }
511+
} |
512+
Get-Partition |
513+
ForEach-Object {
514+
Write-Host "After: $($pvar.Index)"
515+
}
516+
```
517+
518+
Notice that the value of `$pvar` set to the last object in the pipeline for
519+
the second `ForEach-Object` command.
520+
521+
```Output
522+
Before: 1
523+
Before: 2
524+
Before: 0
525+
After: 0
526+
After: 0
527+
After: 0
528+
After: 0
529+
After: 0
530+
After: 0
531+
```
532+
462533
### -ProgressAction
463534

464535
Determines how PowerShell responds to progress updates generated by a script,

0 commit comments

Comments
 (0)