92 lines
1.9 KiB
PowerShell
92 lines
1.9 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Checks whether the specified package has been installed using Chocolatey.
|
|
|
|
.PARAMETER Name
|
|
The name of the package to check.
|
|
#>
|
|
function Test-ChocoPackage {
|
|
[OutputType([bool])]
|
|
param(
|
|
[string] $Name
|
|
);
|
|
|
|
-not [string]::IsNullOrEmpty((choco list --limit-output --exact $name));
|
|
}
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Checks whether a `winget` package with the specified id is installed.
|
|
|
|
.PARAMETER ID
|
|
The id of the package to check.
|
|
#>
|
|
function Test-WingetPackage {
|
|
[OutputType([bool])]
|
|
param(
|
|
[string] $Name,
|
|
[string[]] $ArgumentList
|
|
)
|
|
|
|
& { $null = winget list --accept-source-agreements -e --id $Name @ArgumentList; $?; };
|
|
}
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Checks whether a command with the specified name exists.
|
|
|
|
.PARAMETER Name
|
|
The name of the command to check.
|
|
#>
|
|
function Test-Command {
|
|
param (
|
|
[string] $Name
|
|
)
|
|
|
|
[bool] (Get-Command $Name -ErrorAction SilentlyContinue);
|
|
}
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Checks whether `winget` is working properly.
|
|
#>
|
|
function Test-Winget {
|
|
(Test-Command winget) -and (
|
|
& {
|
|
$output = winget source update winget;
|
|
|
|
$? -and -not ([System.Linq.Enumerable]::Any(
|
|
[string[]]($output),
|
|
[System.Func[string,bool]]{ param($line) $line -eq "Cancelled"; }));
|
|
});
|
|
}
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Checks whether a package with the specified name is installed.
|
|
|
|
.PARAMETER Name
|
|
The name of the package to check.
|
|
#>
|
|
function Test-PSPackage {
|
|
param(
|
|
[string] $Name
|
|
)
|
|
|
|
[bool] (Get-Package $Name -ErrorAction SilentlyContinue);
|
|
}
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Checks whether a module with the specified name is installed.
|
|
|
|
.PARAMETER Name
|
|
The name of the module to check.
|
|
#>
|
|
function Test-PSModule {
|
|
param(
|
|
[string] $Name
|
|
)
|
|
|
|
[bool](Get-Module -ListAvailable $Name -ErrorAction SilentlyContinue);
|
|
}
|