Skip to content

Commit ce4d40c

Browse files
authored
Implement DSC Resources (microsoft#2788)
1 parent 130a2c8 commit ce4d40c

11 files changed

Lines changed: 901 additions & 67 deletions

File tree

.github/actions/spelling/expect.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ ecfr
9393
ecfrbrowse
9494
EFGH
9595
EQU
96+
endregion
9697
errmsg
9798
ESRB
9899
etest
@@ -200,6 +201,7 @@ minschema
200201
missingdependency
201202
MMmmbbbb
202203
monicka
204+
MOF
203205
MPNS
204206
msdownload
205207
msft

src/PowerShell/Microsoft.WinGet.Client/Crescendo/Crescendo.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@
5858
}
5959
]
6060
},
61+
{
62+
"Verb": "Get",
63+
"Noun": "WinGetSettings",
64+
"Platform": [
65+
"Windows"
66+
],
67+
"OriginalName": "winget.exe",
68+
"OriginalCommandElements": [
69+
"settings",
70+
"export"
71+
]
72+
},
6173
{
6274
"Verb": "Add",
6375
"Noun": "WinGetSource",

src/PowerShell/Microsoft.WinGet.Client/Module/Microsoft.WinGet.Client.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ FunctionsToExport = @(
8080
'Disable-WinGetSetting',
8181
'Add-WinGetSource',
8282
'Remove-WinGetSource',
83-
'Reset-WinGetSource'
83+
'Reset-WinGetSource',
84+
'Get-WinGetSettings'
8485
)
8586

8687
# 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.

src/PowerShell/Microsoft.WinGet.Client/Module/Microsoft.WinGet.Client.psm1

Lines changed: 150 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,22 @@ class PowerShellCustomFunctionAttribute : System.Attribute {
99
}
1010
}
1111

12+
<#
13+
.SYNOPSIS
14+
Displays the version of the tool.
1215
16+
.DESCRIPTION
17+
Displays the version of the winget.exe tool.
1318
19+
.INPUTS
20+
None.
21+
22+
.OUTPUTS
23+
None
24+
25+
.EXAMPLE
26+
PS> Get-WinGetVersion
27+
#>
1428
function Get-WinGetVersion
1529
{
1630
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
@@ -79,13 +93,22 @@ PROCESS {
7993
}
8094
}
8195
} # end PROCESS
96+
}
8297

8398
<#
8499
.SYNOPSIS
85-
Displays the version of the tool.
100+
Enables the WinGet setting specified by the `Name` parameter.
86101
87102
.DESCRIPTION
88-
Displays the version of the winget.exe tool.
103+
Enables the WinGet setting specified by the `Name` parameter.
104+
Supported settings:
105+
- LocalManifestFiles
106+
- BypassCertificatePinningForMicrosoftStore
107+
- InstallerHashOverride
108+
- LocalArchiveMalwareScanOverride
109+
110+
.PARAMETER Name
111+
Specifies the name of the setting to be enabled.
89112
90113
.INPUTS
91114
None.
@@ -94,10 +117,8 @@ PROCESS {
94117
None
95118
96119
.EXAMPLE
97-
PS> Get-WinGetVersion
120+
PS> Enable-WinGetSetting -name LocalManifestFiles
98121
#>
99-
}
100-
101122
function Enable-WinGetSetting
102123
{
103124
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
@@ -180,17 +201,22 @@ PROCESS {
180201
}
181202
}
182203
} # end PROCESS
204+
}
183205

184206
<#
185207
.SYNOPSIS
186-
Enables the WinGet setting specified by the `Name` parameter.
208+
Disables the WinGet setting specified by the `Name` parameter.
187209
188210
.DESCRIPTION
189-
Enables the WinGet setting specified by the `Name` parameter.
190-
Supported settings: `LocalManifestFiles`
211+
Disables the WinGet setting specified by the `Name` parameter.
212+
Supported settings:
213+
- LocalManifestFiles
214+
- BypassCertificatePinningForMicrosoftStore
215+
- InstallerHashOverride
216+
- LocalArchiveMalwareScanOverride
191217
192218
.PARAMETER Name
193-
Specifies the name of the setting to be enabled.
219+
Specifies the name of the setting to be disabled.
194220
195221
.INPUTS
196222
None.
@@ -199,13 +225,8 @@ PROCESS {
199225
None
200226
201227
.EXAMPLE
202-
PS> Enable-WinGetSetting -name LocalManifestFiles
228+
PS> Disable-WinGetSetting -name LocalManifestFiles
203229
#>
204-
}
205-
206-
207-
208-
209230
function Disable-WinGetSetting
210231
{
211232
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
@@ -288,29 +309,125 @@ PROCESS {
288309
}
289310
}
290311
} # end PROCESS
312+
}
291313

292314
<#
293315
.SYNOPSIS
294-
Disables the WinGet setting specified by the `Name` parameter.
316+
Get winget settings.
295317
296318
.DESCRIPTION
297-
Disables the WinGet setting specified by the `Name` parameter.
298-
Supported settings: `LocalManifestFiles`
319+
Get the administrator settings values as well as the location of the user settings as json string
299320
300321
.PARAMETER Name
301-
Specifies the name of the setting to be disabled.
322+
None
302323
303324
.INPUTS
304325
None.
305326
306327
.OUTPUTS
307-
None
328+
Prints the export settings json.
308329
309330
.EXAMPLE
310-
PS> Disable-WinGetSetting -name LocalManifestFiles
331+
PS> Get-WinGetSettings
311332
#>
333+
function Get-WinGetSettings
334+
{
335+
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
336+
[CmdletBinding(SupportsShouldProcess)]
337+
338+
param( )
339+
340+
BEGIN {
341+
$__PARAMETERMAP = @{}
342+
$__outputHandlers = @{ Default = @{ StreamOutput = $true; Handler = { $input } } }
343+
}
344+
345+
PROCESS {
346+
$__boundParameters = $PSBoundParameters
347+
$__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name
348+
$__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_})
349+
$__commandArgs = @()
350+
$MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)})
351+
if ($__boundParameters["Debug"]){wait-debugger}
352+
$__commandArgs += 'settings'
353+
$__commandArgs += 'export'
354+
foreach ($paramName in $__boundParameters.Keys|
355+
Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}|
356+
Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) {
357+
$value = $__boundParameters[$paramName]
358+
$param = $__PARAMETERMAP[$paramName]
359+
if ($param) {
360+
if ($value -is [switch]) {
361+
if ($value.IsPresent) {
362+
if ($param.OriginalName) { $__commandArgs += $param.OriginalName }
363+
}
364+
elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue }
365+
}
366+
elseif ( $param.NoGap ) {
367+
$pFmt = "{0}{1}"
368+
if($value -match "\s") { $pFmt = "{0}""{1}""" }
369+
$__commandArgs += $pFmt -f $param.OriginalName, $value
370+
}
371+
else {
372+
if($param.OriginalName) { $__commandArgs += $param.OriginalName }
373+
$__commandArgs += $value | Foreach-Object {$_}
374+
}
375+
}
376+
}
377+
$__commandArgs = $__commandArgs | Where-Object {$_ -ne $null}
378+
if ($__boundParameters["Debug"]){wait-debugger}
379+
if ( $__boundParameters["Verbose"]) {
380+
Write-Verbose -Verbose -Message winget.exe
381+
$__commandArgs | Write-Verbose -Verbose
382+
}
383+
$__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName]
384+
if (! $__handlerInfo ) {
385+
$__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present
386+
}
387+
$__handler = $__handlerInfo.Handler
388+
if ( $PSCmdlet.ShouldProcess("winget.exe $__commandArgs")) {
389+
# check for the application and throw if it cannot be found
390+
if ( -not (Get-Command -ErrorAction Ignore "winget.exe")) {
391+
throw "Cannot find executable 'winget.exe'"
392+
}
393+
if ( $__handlerInfo.StreamOutput ) {
394+
& "winget.exe" $__commandArgs | & $__handler
395+
}
396+
else {
397+
$result = & "winget.exe" $__commandArgs
398+
& $__handler $result
399+
}
400+
}
401+
} # end PROCESS
312402
}
313403

404+
<#
405+
.SYNOPSIS
406+
Add a new source.
407+
408+
.DESCRIPTION
409+
Add a new source. A source provides the data for you to discover and install packages.
410+
Only add a new source if you trust it as a secure location.
411+
412+
.PARAMETER Name
413+
Name of the source.
414+
415+
.PARAMETER Argument
416+
Argument to be given to the source.
417+
418+
.PARAMETER Type
419+
Type of the source.
420+
421+
.INPUTS
422+
None.
423+
424+
.OUTPUTS
425+
None.
426+
427+
.EXAMPLE
428+
PS> Add-WinGetSource -Name Contoso -Argument https://www.contoso.com/cache
429+
430+
#>
314431
function Add-WinGetSource
315432
{
316433
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
@@ -413,37 +530,28 @@ PROCESS {
413530
}
414531
}
415532
} # end PROCESS
533+
}
416534

417535
<#
418536
.SYNOPSIS
419-
Add a new source.
537+
Remove a specific source.
420538
421539
.DESCRIPTION
422-
Add a new source. A source provides the data for you to discover and install packages.
423-
Only add a new source if you trust it as a secure location.
540+
Remove a specific source. The source must already exist to be removed.
424541
425542
.PARAMETER Name
426543
Name of the source.
427544
428-
.PARAMETER Argument
429-
Argument to be given to the source.
430-
431-
.PARAMETER Type
432-
Type of the source.
433-
434545
.INPUTS
435546
None.
436547
437548
.OUTPUTS
438549
None.
439550
440551
.EXAMPLE
441-
PS> Add-WinGetSource -Name Contoso -Argument https://www.contoso.com/cache
552+
PS> Remove-WinGetSource -Name Contoso
442553
443554
#>
444-
}
445-
446-
447555
function Remove-WinGetSource
448556
{
449557
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
@@ -526,13 +634,15 @@ PROCESS {
526634
}
527635
}
528636
} # end PROCESS
637+
}
529638

530639
<#
531640
.SYNOPSIS
532-
Remove a specific source.
641+
Drops existing sources. Without any argument, this command will drop all sources and add the defaults.
533642
534643
.DESCRIPTION
535-
Remove a specific source. The source must already exist to be removed.
644+
Drops existing sources, potentially leaving any local data behind. Without any argument, it will drop all sources and add the defaults.
645+
If a named source is provided, only that source will be dropped.
536646
537647
.PARAMETER Name
538648
Name of the source.
@@ -544,11 +654,12 @@ PROCESS {
544654
None.
545655
546656
.EXAMPLE
547-
PS> Remove-WinGetSource -Name Contoso
657+
PS> Reset-WinGetSource
548658
549-
#>
550-
}
659+
.EXAMPLE
660+
PS> Reset-WinGetSource -Name Contoso
551661
662+
#>
552663
function Reset-WinGetSource
553664
{
554665
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)]
@@ -632,31 +743,6 @@ PROCESS {
632743
}
633744
}
634745
} # end PROCESS
635-
636-
<#
637-
.SYNOPSIS
638-
Drops existing sources. Without any argument, this command will drop all sources and add the defaults.
639-
640-
.DESCRIPTION
641-
Drops existing sources, potentially leaving any local data behind. Without any argument, it will drop all sources and add the defaults.
642-
If a named source is provided, only that source will be dropped.
643-
644-
.PARAMETER Name
645-
Name of the source.
646-
647-
.INPUTS
648-
None.
649-
650-
.OUTPUTS
651-
None.
652-
653-
.EXAMPLE
654-
PS> Reset-WinGetSource
655-
656-
.EXAMPLE
657-
PS> Reset-WinGetSource -Name Contoso
658-
659-
#>
660746
}
661747

662748

0 commit comments

Comments
 (0)