GinShell.Utilities/Public/Test-GsEnvironment.ps1
|
function Test-GsEnvironment { <# .SYNOPSIS Tests whether a specific environment item exists. .PARAMETER Type Kind of item: Variable, Registry, File, Folder, Executable, or Module. .PARAMETER Name The item name or path to check. .EXAMPLE Test-GsEnvironment -Type Module -Name 'Az' .EXAMPLE Test-GsEnvironment -Type File -Name 'C:\config.json' #> [CmdletBinding()] param ( [Parameter(Mandatory)] [ValidateSet('Variable', 'Registry', 'File', 'Folder', 'Executable', 'Module')] [string]$Type, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Name ) switch ($Type) { 'Variable' { return [bool](Get-Item -Path "Env:\$Name" -ErrorAction SilentlyContinue) } 'Registry' { return Test-Path -Path $Name } 'File' { return Test-Path -Path $Name -PathType Leaf } 'Folder' { return Test-Path -Path $Name -PathType Container } 'Executable' { return [bool](Get-Command $Name -ErrorAction SilentlyContinue) } 'Module' { return [bool](Get-Module -Name $Name -ListAvailable) } } } |