Test-PSVersion
SYNOPSIS
Test the PowerShell Version
SYNTAX
Test-PSVersion [[-Version] <Version>] [[-lt] <Version>] [[-le] <Version>] [[-gt] <Version>] [[-ge] <Version>]
[[-eq] <Version>] [[-ne] <Version>] [<CommonParameters>]
DESCRIPTION
This function exists so I can do things differently on older versions of PowerShell. But the reason I test in a function is that I can mock the Version to test the alternative code.
EXAMPLES
EXAMPLE 1
if(Test-PSVersion -ge 3.0) {
ls | where Length -gt 12mb
} else {
ls | Where { $_.Length -gt 12mb }
}
This is just a trivial example to show the usage (you wouldn't really bother for a where-object call)
PARAMETERS
-Version
{{ Fill Version Description }}
Type: System.Version
Parameter Sets: (All)
Aliases:
Required: False
Position: 1
Default value: $PSVersionTable.PSVersion
Accept pipeline input: False
Accept wildcard characters: False
-lt
{{ Fill lt Description }}
Type: System.Version
Parameter Sets: (All)
Aliases:
Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-le
{{ Fill le Description }}
Type: System.Version
Parameter Sets: (All)
Aliases:
Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-gt
{{ Fill gt Description }}
Type: System.Version
Parameter Sets: (All)
Aliases:
Required: False
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ge
{{ Fill ge Description }}
Type: System.Version
Parameter Sets: (All)
Aliases:
Required: False
Position: 5
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-eq
{{ Fill eq Description }}
Type: System.Version
Parameter Sets: (All)
Aliases:
Required: False
Position: 6
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ne
{{ Fill ne Description }}
Type: System.Version
Parameter Sets: (All)
Aliases:
Required: False
Position: 7
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.