< Back

Test-PSFPowerShell

Sun Jan 19, 2020 6:45 pm

NAME Test-PSFPowerShell



SYNOPSIS

Tests for conditions in the PowerShell environment.





SYNTAX

Test-PSFPowerShell [[-PSMinVersion] <Version>] [[-PSMaxVersion] <Version>] [[-Edition] {Desktop | Core}]

[[-OperatingSystem] {Windows | Linux | MacOS}] [-Elevated] [<CommonParameters>]





DESCRIPTION

This helper command can evaluate various runtime conditions, such as:

- PowerShell Version

- PowerShell Edition

- Operating System

- Elevation

This makes it easier to do conditional code.

It also makes it easier to simulate code-paths during pester tests, by mocking this command.





PARAMETERS

-PSMinVersion <Version>

PowerShell must be running under at least this version.



Required? false

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-PSMaxVersion <Version>

PowerShell most not be runnign on a version higher than this.



Required? false

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Edition

PowerShell must be running in the specifioed edition (Core or Desktop)



Required? false

Position? 3

Default value

Accept pipeline input? false

Accept wildcard characters? false



-OperatingSystem

PowerShell must be running on the specified OS.



Required? false

Position? 4

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Elevated [<SwitchParameter>]

PowerShell must be running with elevation.



Note:

This test is only supported on Windows.

On other OS it will automatically succede and assume root privileges.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS

System.Boolean





-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Test-PSFPowerShell -PSMinVersion 5.0



Will return $false, unless the executing powershell version is at least 5.0









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Test-PSFPowerShell -Edition Core



Will return $true, if the current powershell session is a PowerShell core session.









-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Test-PSFPowerShell -Elevated



Will return $false if on windows and not running as admin.

Will return $true otherwise.









-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Test-PSFPowerShell -PSMinVersion 6.1 -OperatingSystem Windows



Will return $false unless executed on a PowerShell 6.1 console running on windows.











RELATED LINKS