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

Prototype creating a WinGet Configuration DSC file in PowerShell #462

Merged
merged 6 commits into from
Dec 4, 2023
Merged
Changes from 2 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
63 changes: 63 additions & 0 deletions src/prototype/WingetCreateMakeDSC.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# This script is a prototype for quickly creating DSC files.

if ($null -eq (Get-InstalledModule -Name Microsoft.Winget.Client))
{
Install-Module Microsoft.Winget.Client
KevinLaMS marked this conversation as resolved.
Show resolved Hide resolved
}

if ($null -eq (Get-InstalledModule -Name powershell-yaml))
{
Install-Module powershell-yaml
KevinLaMS marked this conversation as resolved.
Show resolved Hide resolved
}

[System.Collections.ArrayList]$finalPackages = @()
$configurationVersion = "0.2.0"

$continue = $true
ryfu-msft marked this conversation as resolved.
Show resolved Hide resolved
while ($continue)
ryfu-msft marked this conversation as resolved.
Show resolved Hide resolved
{
$appId = Read-Host "What is the id of your app?"
$findResult = Find-WinGetPackage $appId

if ($findResult.count -ne 0)
{
$index=0
foreach ($package in $findResult)
{
$packageDetails = "[$($index)] $($package.Name) | $($package.Id) | $($package.Version)"
Write-Host $packageDetails
$index++
}
ryfu-msft marked this conversation as resolved.
Show resolved Hide resolved

$selection = -1
$packageSelected = $false
while (-not($packageSelected))
{
$selection = [int](Read-Host "Input the number of the package you want to select")
if (($selection -gt $findResult.count) -or ($selection -lt 0))
KevinLaMS marked this conversation as resolved.
Show resolved Hide resolved
{
Write-Host "Selection is out of range, try again."
}
else
{
$packageSelected = $true
}
}

$selectedPackage = $findResult[$selection]

$unit = @{"resource" = "Microsoft.WinGet.DSC/WinGetPackage"; "directives" = @{"description" = $selectedPackage.Name; "allowPrerelease" = $true; }; "settings" = @{"id" = $selectedPackage.Id; "source"="winget" }}
ryfu-msft marked this conversation as resolved.
Show resolved Hide resolved
$finalPackages.Add($unit)

$continue = (Read-Host "Would you like to add another package? [y/n]") -eq 'y'
}
else
{
Write-Host "No package found matching input criteria." -ForegroundColor DarkYellow
}
}

$fileName = Read-Host "Name of the configuration file (without extension)"
$filePath = Join-Path -Path (Get-Location) -ChildPath "$($fileName).yaml"
ConvertTo-Yaml @{"properties"= @{"resources"=$finalPackages; "configurationVersion"= $configurationVersion}} -OutFile $filePath -Force
KevinLaMS marked this conversation as resolved.
Show resolved Hide resolved
ryfu-msft marked this conversation as resolved.
Show resolved Hide resolved
Write-Host "Configuration file created at: $($filePath)" -ForegroundColor Green
KevinLaMS marked this conversation as resolved.
Show resolved Hide resolved