Prerequisites
Links
Summary
The section ## INPUTS. in reference/7.6/Microsoft.PowerShell.Utility/Clear-Variable.md is wrong or outdated.
It states:
## INPUTS
### None
You can't pipe objects to this cmdlet.
At least since Powershell Version 7.5.5 it's possible to pipe a variable of type System.Management.Automation.PSVariable to the Cmdlet Clear-Variable. The same is true and documented correctly for the Cmdlet Remove-Variable
Details
Short Test Script
This short test shows, that we can pipe a System.Management.Automation.PSVariable to the Cmdlet Clear-Variable
### Running on Powershell Core Edition 7.5.5 (Windows 11 64-bit x64 AMD64 10.0.26200)
$PSVersionTable | Select-Object -Property PSVersion, PSEdition | Format-List
# PSVersion : 7.5.5
# PSEdition : Core
# set string variable
$TestDemoStringVariable = "This is a test string"
# clear the variable with pipe works
Get-Variable TestDemoStringVariable | Clear-Variable
# variable is no cleared to $null
$TestDemoStringVariable -eq $null
### Output ### True
# set variable and assign as
$TestDemoStringVariable = "This is a test string"
$TestDemoStringVariableObject = Get-Variable TestDemoStringVariable
$TestDemoStringVariableObject.GetType().FullName
### Output ### System.Management.Automation.PSVariable
# clear the variable by pipe
$TestDemoStringVariableObject | Clear-Variable
$TestDemoStringVariableObject
### Output ###Name Value
### Output ###---- -----
### Output ###TestDemoStringVariable
# check variable is cleared ($null)
$TestDemoStringVariable -eq $null
### Output ### True
Full Test List
$PSVersionTable.PSVersion.ToString()
### Output ### 7.5.5
$TestDemoStringVariable = "This is a test string"
$TestDemoStringVariable
### Output ### This is a test string
$TestDemoStringVariable.GetType().Name
### Output ### String
(Get-Variable TestDemoStringVariable).GetType().Name
### Output ### PSVariable
Get-Variable TestDemoStringVariable | Clear-Variable
$TestDemoStringVariable
$TestDemoStringVariable.GetType().Name
### Output ### InvalidOperation: You cannot call a method on a null-valued expression.
$TestDemoStringVariable.GetType()
InvalidOperation: You cannot call a method on a null-valued expression.
$TestDemoStringVariable -eq $null
### Output ### True
$TestDemoStringVariable = "This is a test string"
$TestDemoStringVariable
### Output ### This is a test string
$TestDemoStringVariable.GetType().Name
### Output ### String
[PSVariable]"TestDemoStringVariable" | Clear-Variable
$TestDemoStringVariable -eq $null
### Output ### True
$TestDemoStringVariable
[string] $TestDemoStringTypedVariable = "This is a typed string variable"
Get-Variable "TestDemoStringTypedVariable" | Clear-Variable
$TestDemoStringTypedVariable.GetType().Fullname
### Output ### System.String
($TestDemoStringTypedVariable -eq $null)
### Output ### False
$TestDemoStringTypedVariable.Value
($TestDemoStringTypedVariable.Value -eq $null)
### Output ### True
$TestDemoStringVariable = "This is a test string"
$TestDemoStringVariableObject = Get-Variable TestDemoStringVariable
$TestDemoStringVariableObject.GetType().FullName
### Output ### System.Management.Automation.PSVariable
$TestDemoStringVariableObject
### Output ### Name Value
### Output ### ---- -----
### Output ### TestDemoStringVariable This is a test string
$TestDemoStringVariableObject | Clear-Variable
$TestDemoStringVariableObject
### Output ###Name Value
### Output ###---- -----
### Output ###TestDemoStringVariable
$TestDemoStringVariable -eq $null
### Output ### True
Suggested Fix
Change Section ## INPUTS. in reference/7.6/Microsoft.PowerShell.Utility/Clear-Variable.md as piping a System.Management.Automation.PSVariable object is allowed. The old Information None, "You can't pipe objects to this cmdlet." is wrong.
New suggested text for the section ## INPUTS. starting on line 220 in version 7.6:
## INPUTS
### System.Management.Automation.PSVariable
You can pipe a variable object to this cmdlet.
This is the same text used for the section in reference/7.6/Microsoft.PowerShell.Utility/Remove-Variable.md
Prerequisites
Get-Foocmdlet" instead of "Typo."Links
Summary
The section
## INPUTS.inreference/7.6/Microsoft.PowerShell.Utility/Clear-Variable.mdis wrong or outdated.It states:
At least since Powershell Version 7.5.5 it's possible to pipe a variable of type
System.Management.Automation.PSVariableto the CmdletClear-Variable. The same is true and documented correctly for the CmdletRemove-VariableDetails
Short Test Script
This short test shows, that we can pipe a
System.Management.Automation.PSVariableto the CmdletClear-VariableFull Test List
Suggested Fix
Change Section
## INPUTS.inreference/7.6/Microsoft.PowerShell.Utility/Clear-Variable.mdas piping a System.Management.Automation.PSVariable object is allowed. The old InformationNone, "You can't pipe objects to this cmdlet." is wrong.New suggested text for the section
## INPUTS.starting on line 220 in version 7.6:This is the same text used for the section in
reference/7.6/Microsoft.PowerShell.Utility/Remove-Variable.md