Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DSC Resources #2788

Merged
merged 5 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ ecfr
ecfrbrowse
EFGH
EQU
endregion
errmsg
ESRB
etest
Expand Down Expand Up @@ -200,6 +201,7 @@ minschema
missingdependency
MMmmbbbb
monicka
MOF
MPNS
msdownload
msft
Expand Down
12 changes: 12 additions & 0 deletions src/PowerShell/Microsoft.WinGet.Client/Crescendo/Crescendo.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@
}
]
},
{
"Verb": "Get",
"Noun": "WinGetSettings",
"Platform": [
"Windows"
],
"OriginalName": "winget.exe",
"OriginalCommandElements": [
"settings",
"export"
]
},
{
"Verb": "Add",
"Noun": "WinGetSource",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ FunctionsToExport = @(
'Disable-WinGetSetting',
'Add-WinGetSource',
'Remove-WinGetSource',
'Reset-WinGetSource'
'Reset-WinGetSource',
'Get-WinGetSettings'
)

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@ class PowerShellCustomFunctionAttribute : System.Attribute {
}
}

<#
.SYNOPSIS
Displays the version of the tool.

.DESCRIPTION
Displays the version of the winget.exe tool.

.INPUTS
None.

.OUTPUTS
None

.EXAMPLE
PS> Get-WinGetVersion
#>
function Get-WinGetVersion
{
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
Expand Down Expand Up @@ -79,13 +93,22 @@ PROCESS {
}
}
} # end PROCESS
}

<#
.SYNOPSIS
Displays the version of the tool.
Enables the WinGet setting specified by the `Name` parameter.

.DESCRIPTION
Displays the version of the winget.exe tool.
Enables the WinGet setting specified by the `Name` parameter.
Supported settings:
- LocalManifestFiles
- BypassCertificatePinningForMicrosoftStore
- InstallerHashOverride
- LocalArchiveMalwareScanOverride

.PARAMETER Name
Specifies the name of the setting to be enabled.

.INPUTS
None.
Expand All @@ -94,10 +117,8 @@ PROCESS {
None

.EXAMPLE
PS> Get-WinGetVersion
PS> Enable-WinGetSetting -name LocalManifestFiles
#>
}

function Enable-WinGetSetting
{
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
Expand Down Expand Up @@ -180,17 +201,22 @@ PROCESS {
}
}
} # end PROCESS
}

<#
.SYNOPSIS
Enables the WinGet setting specified by the `Name` parameter.
Disables the WinGet setting specified by the `Name` parameter.

.DESCRIPTION
Enables the WinGet setting specified by the `Name` parameter.
Supported settings: `LocalManifestFiles`
Disables the WinGet setting specified by the `Name` parameter.
Supported settings:
- LocalManifestFiles
- BypassCertificatePinningForMicrosoftStore
- InstallerHashOverride
- LocalArchiveMalwareScanOverride

.PARAMETER Name
Specifies the name of the setting to be enabled.
Specifies the name of the setting to be disabled.

.INPUTS
None.
Expand All @@ -199,13 +225,8 @@ PROCESS {
None

.EXAMPLE
PS> Enable-WinGetSetting -name LocalManifestFiles
PS> Disable-WinGetSetting -name LocalManifestFiles
#>
}




function Disable-WinGetSetting
{
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
Expand Down Expand Up @@ -288,29 +309,125 @@ PROCESS {
}
}
} # end PROCESS
}

<#
.SYNOPSIS
Disables the WinGet setting specified by the `Name` parameter.
Get winget settings.

.DESCRIPTION
Disables the WinGet setting specified by the `Name` parameter.
Supported settings: `LocalManifestFiles`
Get the administrator settings values as well as the location of the user settings as json string

.PARAMETER Name
Specifies the name of the setting to be disabled.
None

.INPUTS
None.

.OUTPUTS
None
Prints the export settings json.

.EXAMPLE
PS> Disable-WinGetSetting -name LocalManifestFiles
PS> Get-WinGetSettings
#>
function Get-WinGetSettings
{
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
[CmdletBinding(SupportsShouldProcess)]

param( )

BEGIN {
$__PARAMETERMAP = @{}
$__outputHandlers = @{ Default = @{ StreamOutput = $true; Handler = { $input } } }
}

PROCESS {
$__boundParameters = $PSBoundParameters
$__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name
$__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_})
$__commandArgs = @()
$MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)})
if ($__boundParameters["Debug"]){wait-debugger}
$__commandArgs += 'settings'
$__commandArgs += 'export'
foreach ($paramName in $__boundParameters.Keys|
Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}|
Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) {
$value = $__boundParameters[$paramName]
$param = $__PARAMETERMAP[$paramName]
if ($param) {
if ($value -is [switch]) {
if ($value.IsPresent) {
if ($param.OriginalName) { $__commandArgs += $param.OriginalName }
}
elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue }
}
elseif ( $param.NoGap ) {
$pFmt = "{0}{1}"
if($value -match "\s") { $pFmt = "{0}""{1}""" }
$__commandArgs += $pFmt -f $param.OriginalName, $value
}
else {
if($param.OriginalName) { $__commandArgs += $param.OriginalName }
$__commandArgs += $value | Foreach-Object {$_}
}
}
}
$__commandArgs = $__commandArgs | Where-Object {$_ -ne $null}
if ($__boundParameters["Debug"]){wait-debugger}
if ( $__boundParameters["Verbose"]) {
Write-Verbose -Verbose -Message winget.exe
$__commandArgs | Write-Verbose -Verbose
}
$__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName]
if (! $__handlerInfo ) {
$__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present
}
$__handler = $__handlerInfo.Handler
if ( $PSCmdlet.ShouldProcess("winget.exe $__commandArgs")) {
# check for the application and throw if it cannot be found
if ( -not (Get-Command -ErrorAction Ignore "winget.exe")) {
throw "Cannot find executable 'winget.exe'"
}
if ( $__handlerInfo.StreamOutput ) {
& "winget.exe" $__commandArgs | & $__handler
}
else {
$result = & "winget.exe" $__commandArgs
& $__handler $result
}
}
} # end PROCESS
}

<#
.SYNOPSIS
Add a new source.

.DESCRIPTION
Add a new source. A source provides the data for you to discover and install packages.
Only add a new source if you trust it as a secure location.

.PARAMETER Name
Name of the source.

.PARAMETER Argument
Argument to be given to the source.

.PARAMETER Type
Type of the source.

.INPUTS
None.

.OUTPUTS
None.

.EXAMPLE
PS> Add-WinGetSource -Name Contoso -Argument https://www.contoso.com/cache

#>
function Add-WinGetSource
{
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
Expand Down Expand Up @@ -413,37 +530,28 @@ PROCESS {
}
}
} # end PROCESS
}

<#
.SYNOPSIS
Add a new source.
Remove a specific source.

.DESCRIPTION
Add a new source. A source provides the data for you to discover and install packages.
Only add a new source if you trust it as a secure location.
Remove a specific source. The source must already exist to be removed.

.PARAMETER Name
Name of the source.

.PARAMETER Argument
Argument to be given to the source.

.PARAMETER Type
Type of the source.

.INPUTS
None.

.OUTPUTS
None.

.EXAMPLE
PS> Add-WinGetSource -Name Contoso -Argument https://www.contoso.com/cache
PS> Remove-WinGetSource -Name Contoso

#>
}


function Remove-WinGetSource
{
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
Expand Down Expand Up @@ -526,13 +634,15 @@ PROCESS {
}
}
} # end PROCESS
}

<#
.SYNOPSIS
Remove a specific source.
Drops existing sources. Without any argument, this command will drop all sources and add the defaults.

.DESCRIPTION
Remove a specific source. The source must already exist to be removed.
Drops existing sources, potentially leaving any local data behind. Without any argument, it will drop all sources and add the defaults.
If a named source is provided, only that source will be dropped.

.PARAMETER Name
Name of the source.
Expand All @@ -544,11 +654,12 @@ PROCESS {
None.

.EXAMPLE
PS> Remove-WinGetSource -Name Contoso
PS> Reset-WinGetSource

#>
}
.EXAMPLE
PS> Reset-WinGetSource -Name Contoso

#>
function Reset-WinGetSource
{
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
Expand Down Expand Up @@ -632,31 +743,6 @@ PROCESS {
}
}
} # end PROCESS

<#
.SYNOPSIS
Drops existing sources. Without any argument, this command will drop all sources and add the defaults.

.DESCRIPTION
Drops existing sources, potentially leaving any local data behind. Without any argument, it will drop all sources and add the defaults.
If a named source is provided, only that source will be dropped.

.PARAMETER Name
Name of the source.

.INPUTS
None.

.OUTPUTS
None.

.EXAMPLE
PS> Reset-WinGetSource

.EXAMPLE
PS> Reset-WinGetSource -Name Contoso

#>
}


Loading